mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +00:00
Expr: Warn on count underflow for c -= 1 and c = c - 1
I've skipped treating overflows as warnings, as ++ wrapping around at 0 doesn't currently trigger a runtime error and might be expected to be quiet and silently wrap. Closes #2486
This commit is contained in:
parent
a07b0c333f
commit
e48618e244
7 changed files with 67 additions and 2 deletions
36
testing/btest/language/count-underflow.zeek
Normal file
36
testing/btest/language/count-underflow.zeek
Normal file
|
@ -0,0 +1,36 @@
|
|||
# @TEST-EXEC: zeek -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
|
||||
|
||||
global count_max: count = 0xffffffffffffffff;
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
local c1 = 0;
|
||||
--c1;
|
||||
print fmt("local c1 = 0; --c1; c1 == %s; %s", c1, c1 == count_max);
|
||||
|
||||
local c2 = 0;
|
||||
c2 -= 1;
|
||||
print fmt("local c2 = 0; c2 -= 1; c2 == %s; %s", c2, c2 == count_max);
|
||||
|
||||
local c3 = 0;
|
||||
c3 = c3 - 1;
|
||||
print fmt("local c3 = 0; c3 = c3 - 1; c3 == %s; %s", c3, c3 == count_max);
|
||||
|
||||
# This also triggers a warning now;
|
||||
print "1 - 2", 1 - 2;
|
||||
|
||||
# The following ones all overflow back to 0, but do not log a warning.
|
||||
local c4 = count_max;
|
||||
++c4;
|
||||
print fmt("local c4 = count_max; ++c4; c4 == %s; %s", c4, c4 == 0);
|
||||
|
||||
local c5 = count_max;
|
||||
c5 += 1;
|
||||
print fmt("local c5 = count_max; c5 += 1; c5 == %s; %s", c5, c5 == 0);
|
||||
|
||||
local c6 = count_max;
|
||||
c6 = c6 + 1;
|
||||
print fmt("local c6 = count_max; c6 = c6 + 1; c6 == %s; %s", c6, c6 == 0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue