log errors on expressions evaluation, only when the return value is NAN or INFINITY
Costa Tsaousis (ktsaou) committed
Nov 12, 2016 at 19:40 UTC
ce020f0840110bdd5bc8ffab523a3a3771fa0afb
1 file changed
+14
-19
src/eval.c
+14
-19
@@ -59,20 +59,6 @@ static inline void print_parsed_as_constant(BUFFER *out, calculated_number n);
59
// ----------------------------------------------------------------------------
60
// evaluation of expressions
61
62
-static inline calculated_number eval_check_number(calculated_number n, int *error) {
63
- if(unlikely(isnan(n))) {
64
- *error = EVAL_ERROR_VALUE_IS_NAN;
65
- return 0;
66
- }
67
-
68
- if(unlikely(isinf(n))) {
69
- *error = EVAL_ERROR_VALUE_IS_INFINITE;
70
- return 0;
71
- }
72
-
73
- return n;
74
-}
75
-
62
static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABLE *v, int *error) {
63
static uint32_t this_hash = 0, now_hash = 0, after_hash = 0, before_hash = 0, status_hash = 0, removed_hash = 0, uninitialized_hash = 0, undefined_hash = 0, clear_hash = 0, warning_hash = 0, critical_hash = 0;
64
calculated_number n;
@@ -187,7 +173,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL
173
}
174
175
*error = EVAL_ERROR_UNKNOWN_VARIABLE;
190
- buffer_sprintf(exp->error_msg, "unknown variable '%s'", v->name);
176
+ buffer_sprintf(exp->error_msg, "[ undefined variable '%s' ] ", v->name);
177
return 0;
178
}
179
@@ -213,7 +199,6 @@ static inline calculated_number eval_value(EVAL_EXPRESSION *exp, EVAL_VALUE *v,
199
break;
200
}
201
216
- // return eval_check_number(n, error);
202
return n;
203
}
204
@@ -362,7 +347,6 @@ static inline calculated_number eval_node(EVAL_EXPRESSION *exp, EVAL_NODE *op, i
347
348
calculated_number n = operators[op->operator].eval(exp, op, error);
349
365
- // return eval_check_number(n, error);
350
return n;
351
}
352
@@ -1067,8 +1051,19 @@ int expression_evaluate(EVAL_EXPRESSION *exp) {
1051
buffer_reset(exp->error_msg);
1052
exp->result = eval_node(exp, (EVAL_NODE *)exp->nodes, &exp->error);
1053
1070
- if(exp->error == EVAL_ERROR_OK)
1071
- exp->result = eval_check_number(exp->result, &exp->error);
1054
+ if(unlikely(isnan(exp->result))) {
1055
+ if(exp->error == EVAL_ERROR_OK)
1056
+ exp->error = EVAL_ERROR_VALUE_IS_NAN;
1057
+ }
1058
+ else if(unlikely(isinf(exp->result))) {
1059
+ if(exp->error == EVAL_ERROR_OK)
1060
+ exp->error = EVAL_ERROR_VALUE_IS_INFINITE;
1061
+ }
1062
+ else if(unlikely(exp->error == EVAL_ERROR_UNKNOWN_VARIABLE)) {
1063
+ // although there is an unknown variable
1064
+ // the expression was evaluated successfully
1065
+ exp->error = EVAL_ERROR_OK;
1066
+ }
1067
1068
if(exp->error != EVAL_ERROR_OK) {
1069
exp->result = NAN;