zeek/testing/btest/core/div-by-zero.bro
Jon Siwek 1750e351c4 Prevent division/modulo by zero in scripts.
Integral/floating-point division/modulo by zero in C++ is undefined
behavior, so to prevent such cases in a script from crashing Bro,
they're now reported as an error (with script location information) and
the event handler in which it occurred returns immediately.
2013-09-20 16:36:00 -05:00

36 lines
543 B
Text

# @TEST-EXEC: bro -b %INPUT >out 2>&1
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
event div_int(a: int, b: int)
{
print a / b;
}
event div_count(a: count, b: count)
{
print a / b;
}
event div_double(a: double, b: double)
{
print a / b;
}
event mod_int(a: int, b: int)
{
print a % b;
}
event mod_count(a: count, b: count)
{
print a % b;
}
event bro_init()
{
event div_int(10, 0);
event div_count(10, 0);
event div_double(10.0, 0.0);
event mod_int(10, 0);
event mod_count(10, 0);
}