mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
Expr: Fix folding of pattern values to support == and !=
The fatal error is actually triggered at runtime, so it's a bit dangerous for users, but not sure there's many use-cases to compare vectors of patterns. Closes #4084
This commit is contained in:
parent
9a4791f9e9
commit
cd8adb3da5
3 changed files with 21 additions and 4 deletions
16
src/Expr.cc
16
src/Expr.cc
|
@ -925,12 +925,20 @@ ValPtr BinaryExpr::PatternFold(Val* v1, Val* v2) const {
|
|||
const RE_Matcher* re1 = v1->AsPattern();
|
||||
const RE_Matcher* re2 = v2->AsPattern();
|
||||
|
||||
if ( tag != EXPR_AND && tag != EXPR_OR )
|
||||
ValPtr res;
|
||||
if ( tag == EXPR_AND || tag == EXPR_OR ) {
|
||||
RE_Matcher* matcher = tag == EXPR_AND ? RE_Matcher_conjunction(re1, re2) : RE_Matcher_disjunction(re1, re2);
|
||||
res = make_intrusive<PatternVal>(matcher);
|
||||
}
|
||||
else if ( tag == EXPR_EQ || tag == EXPR_NE ) {
|
||||
bool cmp = strcmp(re1->PatternText(), re2->PatternText());
|
||||
res = val_mgr->Bool(tag == EXPR_EQ ? cmp == 0 : cmp != 0);
|
||||
}
|
||||
else {
|
||||
BadTag("BinaryExpr::PatternFold");
|
||||
}
|
||||
|
||||
RE_Matcher* res = tag == EXPR_AND ? RE_Matcher_conjunction(re1, re2) : RE_Matcher_disjunction(re1, re2);
|
||||
|
||||
return make_intrusive<PatternVal>(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
ValPtr BinaryExpr::SetFold(Val* v1, Val* v2) const {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue