mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
Bad record constructor initializers now give an error (addresses #34).
As opposed to a segfault.
This commit is contained in:
parent
75278af8a1
commit
32239ea633
3 changed files with 23 additions and 10 deletions
10
src/Expr.cc
10
src/Expr.cc
|
@ -3286,7 +3286,11 @@ RecordConstructorExpr::RecordConstructorExpr(ListExpr* constructor_list)
|
|||
|
||||
Val* RecordConstructorExpr::InitVal(const BroType* t, Val* aggr) const
|
||||
{
|
||||
RecordVal* rv = Eval(0)->AsRecordVal();
|
||||
Val* v = Eval(0);
|
||||
|
||||
if ( v )
|
||||
{
|
||||
RecordVal* rv = v->AsRecordVal();
|
||||
RecordVal* ar = rv->CoerceTo(t->AsRecordType(), aggr);
|
||||
|
||||
if ( ar )
|
||||
|
@ -3294,13 +3298,11 @@ Val* RecordConstructorExpr::InitVal(const BroType* t, Val* aggr) const
|
|||
Unref(rv);
|
||||
return ar;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Error("bad record initializer");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Val* RecordConstructorExpr::Fold(Val* v) const
|
||||
{
|
||||
|
|
3
testing/btest/Baseline/language.record-bad-ctor/out
Normal file
3
testing/btest/Baseline/language.record-bad-ctor/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-bad-ctor/record-bad-ctor.bro, line 6: no type given (asdfasdf)
|
||||
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-bad-ctor/record-bad-ctor.bro, line 7: uninitialized list value ($ports=asdfasdf)
|
||||
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-bad-ctor/record-bad-ctor.bro, line 7: bad record initializer ([$ports=asdfasdf])
|
8
testing/btest/language/record-bad-ctor.bro
Normal file
8
testing/btest/language/record-bad-ctor.bro
Normal file
|
@ -0,0 +1,8 @@
|
|||
# @TEST-EXEC-FAIL: bro -b %INPUT >out 2>&1
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||
|
||||
# At least shouldn't crash Bro, just report the invalid record ctor.
|
||||
|
||||
global asdfasdf;
|
||||
const blah = [$ports=asdfasdf];
|
||||
print blah;
|
Loading…
Add table
Add a link
Reference in a new issue