commit 7fd9e99: [Fix] Fix expressions logic for and/or and float values
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Jul 16 13:42:04 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-07-16 14:41:17 +0100
URL: https://github.com/rspamd/rspamd/commit/7fd9e99c6c1884593eb17dcb71734701b95c726a (HEAD -> master)
[Fix] Fix expressions logic for and/or and float values
---
src/libserver/composites/composites.cxx | 6 +++++-
src/libutil/expression.c | 9 ++++-----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/libserver/composites/composites.cxx b/src/libserver/composites/composites.cxx
index 1d3c13a97..b03edaf71 100644
--- a/src/libserver/composites/composites.cxx
+++ b/src/libserver/composites/composites.cxx
@@ -747,7 +747,7 @@ rspamd_composite_expr_process(void *ud, rspamd_expression_atom_t *atom) -> doubl
else {
rc = process_single_symbol(cd, sym, &ms, comp_atom);
- if (rc) {
+ if (fabs(rc) > epsilon) {
process_symbol_removal(atom,
cd,
ms,
@@ -821,6 +821,10 @@ composites_foreach_callback(gpointer key, gpointer value, void *data)
return;
}
+ msg_debug_composites ("%s: start processing composite %s",
+ cd->metric_res->name,
+ cd->composite->sym.c_str());
+
rc = rspamd_process_expression(comp->expr, RSPAMD_EXPRESSION_FLAG_NOOPT,
cd);
diff --git a/src/libutil/expression.c b/src/libutil/expression.c
index fc967f404..553767c3a 100644
--- a/src/libutil/expression.c
+++ b/src/libutil/expression.c
@@ -29,7 +29,6 @@
#define MIN_RESORT_EVALS 50
#define MAX_RESORT_EVALS 150
-#define DOUBLE_EPSILON 1e-9
enum rspamd_expression_elt_type {
ELT_OP = 0,
@@ -1232,7 +1231,7 @@ rspamd_ast_do_unary_op (struct rspamd_expression_elt *elt, gdouble operand)
switch (elt->p.op.op) {
case OP_NOT:
- ret = fabs (operand) > DOUBLE_EPSILON ? 0.0 : 1.0;
+ ret = fabs (operand) > DBL_EPSILON ? 0.0 : 1.0;
break;
default:
g_assert_not_reached ();
@@ -1306,10 +1305,10 @@ rspamd_ast_do_nary_op (struct rspamd_expression_elt *elt, gdouble val, gdouble a
ret = acc * val;
break;
case OP_AND:
- ret = (acc * val);
+ ret = (acc > DBL_EPSILON) && (val > DBL_EPSILON);
break;
case OP_OR:
- ret = (acc + val);
+ ret = (acc > DBL_EPSILON) || (val > DBL_EPSILON);
break;
default:
case OP_NOT:
@@ -1355,7 +1354,7 @@ rspamd_ast_process_node (struct rspamd_expression *e, GNode *node,
elt->value = process_data->process_closure (process_data->ud, elt->p.atom);
- if (fabs (elt->value) > 1e-9) {
+ if (fabs (elt->value) > DBL_EPSILON) {
elt->p.atom->hits ++;
if (process_data->trace) {
More information about the Commits
mailing list