ChaiScript/unittests/modulo_by_zero_protection.chai
leftibot 9237acbbb9
Fix #634: Add divide-by-zero check for modulo assignment operator (#672)
The assign_remainder (%=) case in Boxed_Number::go was missing the
check_divide_by_zero guard, causing a hardware SIGFPE on integer
modulo by zero. Also moved a misplaced check_divide_by_zero from
assign_bitwise_and (&=) where it was erroneous. Additionally, the
catch block in Equation_AST_Node::eval_internal was masking the
arithmetic_error exception as a generic "unsupported operation" error;
arithmetic_error is now re-thrown to provide the correct error message.

Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 16:28:41 -06:00

17 lines
322 B
ChaiScript

// modulo by zero should throw, not crash
try {
3 % 0
assert_true(false)
} catch (e) {
assert_equal("Arithmetic error: divide by zero", e.what())
}
// assign-modulo by zero should also throw
var x = 3;
try {
x %= 0
assert_true(false)
} catch (e) {
assert_equal("Arithmetic error: divide by zero", e.what())
}