mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00

* origin/topic/vern/zam-aggr-change-in-loop:
fix for ZAM optimization when an aggregate is modified inside of a loop
(cherry picked from commit 2255fa23b8
)
38 lines
899 B
Text
38 lines
899 B
Text
# @TEST-DOC: Regression test for an aggregate in a CSE changing inside a loop
|
|
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
|
|
# @TEST-EXEC: zeek -b -O ZAM %INPUT >output
|
|
# @TEST-EXEC: btest-diff output
|
|
|
|
type Data: record {
|
|
hash: string;
|
|
};
|
|
|
|
global map: table[string] of Data;
|
|
|
|
function traverse_map(hash: string)
|
|
{
|
|
local tmp = map[hash];
|
|
|
|
if ( tmp$hash == "" )
|
|
return;
|
|
|
|
while ( tmp$hash in map )
|
|
{
|
|
# Prior to the fix, the value of tmp$hash computed in the
|
|
# earlier "if" statement was used here, rather than the
|
|
# optimizer recognizing that "tmp" can have changed at this
|
|
# point due to the loop, and thus that value can be stale.
|
|
# That led to an infinite loop here.
|
|
tmp = map[tmp$hash];
|
|
print tmp;
|
|
}
|
|
}
|
|
|
|
event zeek_init()
|
|
{
|
|
map["foo"] = Data($hash="bar");
|
|
map["bar"] = Data($hash="bletch");
|
|
map["bletch"] = Data($hash="xyzzy");
|
|
traverse_map("foo");
|
|
print "done";
|
|
}
|