Support appending to vector of any

For consistency, since it already works to assign to an index within
vector of any.
This commit is contained in:
Jon Siwek 2018-11-07 11:46:34 -06:00
parent 808f1d1524
commit ca014d6e35
5 changed files with 31 additions and 3 deletions

View file

@ -1,4 +1,8 @@
2.6-beta2-80 | 2018-11-07 11:46:34 -0600
* Support appending to vector of any (Jon Siwek, Corelight)
2.6-beta2-79 | 2018-11-07 10:27:00 -0600
* Fix coding conventions nits/typos (Vern Paxson, Corelight)

View file

@ -1 +1 @@
2.6-beta2-79
2.6-beta2-80

View file

@ -1485,8 +1485,9 @@ AddToExpr::AddToExpr(Expr* arg_op1, Expr* arg_op2)
ExprError("appending non-arithmetic to arithmetic vector");
}
else if ( bt1 != bt2 )
ExprError("incompatible vector append");
else if ( bt1 != bt2 && bt1 != TYPE_ANY )
ExprError(fmt("incompatible vector append: %s and %s",
type_name(bt1), type_name(bt2)));
else
SetType(op1->Type()->Ref());

View file

@ -0,0 +1 @@
[0, 1, 2, 3]

View file

@ -0,0 +1,22 @@
# @TEST-EXEC: bro -b %INPUT >out
# @TEST-EXEC: btest-diff out
function assign(v: vector of any)
{
v[|v|] = |v|;
}
function append(v: vector of any)
{
v += |v|;
}
event bro_init()
{
local v: vector of count;
assign(v);
assign(v);
append(v);
append(v);
print v;
}