diff --git a/src/Expr.cc b/src/Expr.cc index 4c3c7a536a..a86f86b9c4 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -456,7 +456,13 @@ Val* UnaryExpr::Eval(Frame* f) const if ( is_vector(v) ) { VectorVal* v_op = v->AsVectorVal(); - VectorVal* result = new VectorVal(Type()->AsVectorType()); + VectorType* out_t; + if ( Type()->Tag() == TYPE_ANY ) + out_t = v->Type()->AsVectorType(); + else + out_t = Type()->AsVectorType(); + + VectorVal* result = new VectorVal(out_t); for ( unsigned int i = 0; i < v_op->Size(); ++i ) { diff --git a/testing/btest/core/vector-assignment.bro b/testing/btest/core/vector-assignment.bro new file mode 100644 index 0000000000..d1f02c124f --- /dev/null +++ b/testing/btest/core/vector-assignment.bro @@ -0,0 +1,19 @@ +# @TEST-EXEC: bro %INPUT + +# This regression test checks a special case in the vector code. In this case +# UnaryExpr will be called with a Type() of any. Tests succeeds if it does not +# crash Bro. + +type OptionCacheValue: record { + val: any; +}; + +function set_me(val: any) { + local a = OptionCacheValue($val=val); + print a; +} + +event bro_init() { + local b: vector of count = {1, 2, 3}; + set_me(b); +}