mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Catch if &add_func/&delete_func is applied to IDs that don't have values.
We do to allow adding &add_func to a global that's not immediately initialized, as a later redef may fix that. Closes #467.
This commit is contained in:
parent
5816ea27e9
commit
45bef16be0
3 changed files with 24 additions and 0 deletions
|
@ -220,6 +220,13 @@ void ID::SetVal(ExprPtr ev, InitClass c)
|
||||||
if ( ! a )
|
if ( ! a )
|
||||||
Internal("no add/delete function in ID::SetVal");
|
Internal("no add/delete function in ID::SetVal");
|
||||||
|
|
||||||
|
if ( ! val )
|
||||||
|
{
|
||||||
|
Error(fmt("%s initializer applied to ID without value",
|
||||||
|
(c == INIT_EXTRA ? "+=" : "-="), this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
EvalFunc(a->GetExpr(), std::move(ev));
|
EvalFunc(a->GetExpr(), std::move(ev));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
error in /Users/robin/bro/master/testing/btest/.tmp/language.global-unset-addto/global-unset-addto.zeek, line 4: += initializer applied to ID without value (a)
|
||||||
|
error in /Users/robin/bro/master/testing/btest/.tmp/language.global-unset-addto/global-unset-addto.zeek, line 5: -= initializer applied to ID without value (b)
|
15
testing/btest/language/global-unset-addto.zeek
Normal file
15
testing/btest/language/global-unset-addto.zeek
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# @TEST-EXEC-FAIL: zeek -b %INPUT >output 2>&1
|
||||||
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output
|
||||||
|
|
||||||
|
global a: count &add_func = function(old: count, new: count): count { return 3; };
|
||||||
|
global b: count &delete_func = function(old: count, new: count): count { return 3; };
|
||||||
|
|
||||||
|
redef a += 13;
|
||||||
|
redef b -= 13;
|
||||||
|
|
||||||
|
# The following is ok.
|
||||||
|
global c: count &redef &add_func = function(old: count, new: count): count { return 3; };
|
||||||
|
redef c = 0;
|
||||||
|
redef c += 13;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue