From 431932d8d63a0f85694c1ec5ec43435a048ffff7 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 9 Oct 2012 15:24:04 +0200 Subject: bugfix: in (non)equal comparisons the position of arrays influenced result This behaviour is OK for "contains"-type of comparisons (which have quite different semantics), but not for == and <>, which shall be commutative. This has been fixed now, so there is no difference any longer if the constant string array is the left or right hand operand. We solved this via the optimizer, as it keeps the actual script execution code small. --- grammar/rainerscript.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 7e75326c..ad6a32e8 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -1173,6 +1173,8 @@ evalVar(struct cnfvar *var, void *usrptr, struct var *ret) * that one one comparison is true, the whole construct is true. * TODO: we can obviously optimize this process. One idea is to * compile a regex, which should work faster than serial comparison. + * Note: compiling a regex does NOT work at all. I experimented with that + * and it was generally 5 to 10 times SLOWER than what we do here... */ static int evalStrArrayCmp(es_str_t *estr_l, struct cnfarray* ar, int cmpop) @@ -1756,7 +1758,6 @@ cnfexprPrint(struct cnfexpr *expr, int indent) struct cnffunc *func; int i; - dbgprintf("expr %p, indent %d, type '%c'\n", expr, indent, expr->nodetype); switch(expr->nodetype) { case CMP_EQ: cnfexprPrint(expr->l, indent+1); @@ -2322,6 +2323,7 @@ void cnfexprOptimize(struct cnfexpr *expr) { long long ln, rn; + struct cnfexpr *exprswap; dbgprintf("optimize expr %p, type '%c'(%u)\n", expr, expr->nodetype, expr->nodetype); switch(expr->nodetype) { @@ -2358,6 +2360,19 @@ cnfexprOptimize(struct cnfexpr *expr) ((struct cnfnumval*)expr)->val = ln % rn; } break; + case CMP_NE: + case CMP_EQ: + if(expr->l->nodetype == 'A') { + if(expr->r->nodetype == 'A') { + parser_errmsg("warning: '==' or '<>' " + "comparison of two constant string " + "arrays makes no sense"); + } else { /* swap for simpler execution step */ + exprswap = expr->l; + expr->l = expr->r; + expr->r = exprswap; + } + } default:/* nodetype we cannot optimize */ break; } -- cgit v1.2.3 From d91e8c31a1e342eb15b0839b9e721730fcad0549 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 11 Oct 2012 12:14:55 +0200 Subject: bugfix: some config processing warning messages were treated as errors --- grammar/rainerscript.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index ad6a32e8..a98277af 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -2186,10 +2186,14 @@ cnfstmtNewAct(struct nvlst *lst) { struct cnfstmt* cnfstmt; char namebuf[256]; + rsRetVal localRet; if((cnfstmt = cnfstmtNew(S_ACT)) == NULL) goto done; - if(actionNewInst(lst, &cnfstmt->d.act) != RS_RET_OK) { - // TODO:RS_RET_WARN? + localRet = actionNewInst(lst, &cnfstmt->d.act); + if(localRet == RS_RET_OK_WARN) { + parser_errmsg("warnings occured in file '%s' around line %d", + cnfcurrfn, yylineno); + } else if(actionNewInst(lst, &cnfstmt->d.act) != RS_RET_OK) { parser_errmsg("errors occured in file '%s' around line %d", cnfcurrfn, yylineno); cnfstmt->nodetype = S_NOP; /* disable action! */ -- cgit v1.2.3 From 9fa59604e94f72225180e5fe28d18c4ec3374d61 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 11 Oct 2012 12:22:49 +0200 Subject: bugfixes in regards to action() - bugfix: small memory leak when processing action() statements - bugfix: unknown action() parameters were not reported --- grammar/rainerscript.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index a98277af..be568238 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -2203,6 +2203,8 @@ cnfstmtNewAct(struct nvlst *lst) modGetName(cnfstmt->d.act->pMod)); namebuf[255] = '\0'; /* be on safe side */ cnfstmt->printable = (uchar*)strdup(namebuf); + nvlstChkUnused(lst); + nvlstDestruct(lst); done: return cnfstmt; } -- cgit v1.2.3 From 1b7e8bd1a8c33f317de66dafed4db16923ae394b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 11 Oct 2012 12:38:17 +0200 Subject: fix regression introduced by last commit action object was created twice, resulting in memleak --- grammar/rainerscript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grammar/rainerscript.c') diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index be568238..9483e116 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -2193,7 +2193,7 @@ cnfstmtNewAct(struct nvlst *lst) if(localRet == RS_RET_OK_WARN) { parser_errmsg("warnings occured in file '%s' around line %d", cnfcurrfn, yylineno); - } else if(actionNewInst(lst, &cnfstmt->d.act) != RS_RET_OK) { + } else if(localRet != RS_RET_OK) { parser_errmsg("errors occured in file '%s' around line %d", cnfcurrfn, yylineno); cnfstmt->nodetype = S_NOP; /* disable action! */ -- cgit v1.2.3