mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
BIT-1280: Fix checking vector indices via "in".
$ cat test.bro local vec: vector of string = { "zero" }; vec[2] = "two"; print 0 in vec, 1 in vec, 2 in vec; $ bro -b test.bro T, F, T
This commit is contained in:
parent
832a2b7bab
commit
e5f75cde93
3 changed files with 37 additions and 3 deletions
12
src/Expr.cc
12
src/Expr.cc
|
@ -636,7 +636,7 @@ Val* BinaryExpr::Eval(Frame* f) const
|
|||
return v_result;
|
||||
}
|
||||
|
||||
if ( is_vec1 || is_vec2 )
|
||||
if ( IsVector(Type()->Tag()) && (is_vec1 || is_vec2) )
|
||||
{ // fold vector against scalar
|
||||
VectorVal* vv = (is_vec1 ? v1 : v2)->AsVectorVal();
|
||||
VectorVal* v_result = new VectorVal(Type()->AsVectorType());
|
||||
|
@ -4703,8 +4703,14 @@ Val* InExpr::Fold(Val* v1, Val* v2) const
|
|||
v2->Type()->Tag() == TYPE_SUBNET )
|
||||
return new Val(v2->AsSubNetVal()->Contains(v1->AsAddr()), TYPE_BOOL);
|
||||
|
||||
TableVal* vt = v2->AsTableVal();
|
||||
if ( vt->Lookup(v1, false) )
|
||||
Val* res;
|
||||
|
||||
if ( is_vector(v2) )
|
||||
res = v2->AsVectorVal()->Lookup(v1);
|
||||
else
|
||||
res = v2->AsTableVal()->Lookup(v1, false);
|
||||
|
||||
if ( res )
|
||||
return new Val(1, TYPE_BOOL);
|
||||
else
|
||||
return new Val(0, TYPE_BOOL);
|
||||
|
|
11
testing/btest/Baseline/language.vector-in-operator/out
Normal file
11
testing/btest/Baseline/language.vector-in-operator/out
Normal file
|
@ -0,0 +1,11 @@
|
|||
[zero, one, , , , five, , seven]
|
||||
vec[0] = zero.exe
|
||||
vec[1] = one.exe
|
||||
vec[2] = <not set>
|
||||
vec[3] = <not set>
|
||||
vec[4] = <not set>
|
||||
vec[5] = five.exe
|
||||
vec[6] = <not set>
|
||||
vec[7] = seven.exe
|
||||
vec[8] = <not set>
|
||||
vec[9] = <not set>
|
17
testing/btest/language/vector-in-operator.bro
Normal file
17
testing/btest/language/vector-in-operator.bro
Normal file
|
@ -0,0 +1,17 @@
|
|||
# @TEST-EXEC: bro -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
local ten = "0123456789";
|
||||
local vec: vector of string = { "zero", "one" };
|
||||
local n = 0;
|
||||
vec[5] = "five";
|
||||
vec[7] = "seven";
|
||||
print vec;
|
||||
vec = vec + ".exe";
|
||||
|
||||
for ( c in ten )
|
||||
{
|
||||
local is_set: bool = (n in vec);
|
||||
print fmt("vec[%s] = %s", n, is_set ? vec[n] : "<not set>");
|
||||
++n;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue