Hi, I found a false negative in Cppcheck 2.21.0 when a boolean comparison result is multiplied into the divisor.
Affected tool
Cppcheck 2.21.0
Affected checker
Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond)
Minimal reproducer
int divide_by_boolean_product(int x, int y) { int divisor = (x < 0) * y; return 1 / divisor; }
Reproduction command
cppcheck --version cppcheck --enable=warning --std=c11 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-boolean-product.c
Current behavior
Cppcheck produces neither a zerodiv nor a zerodivcond diagnostic. The checker report lists CheckOther::checkZeroDivision as active.
zerodiv
zerodivcond
CheckOther::checkZeroDivision
Expected behavior
Cppcheck should report a division-by-zero diagnostic at line 3 because x >= 0 makes (x < 0) and therefore divisor equal to zero.
x >= 0
(x < 0)
divisor
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15059
Log in to post a comment.
Hi, I found a false negative in Cppcheck 2.21.0 when a boolean comparison result is multiplied into the divisor.
Affected tool
Cppcheck 2.21.0Affected checker
Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond)Minimal reproducer
Reproduction command
Current behavior
Cppcheck produces neither a
zerodivnor azerodivconddiagnostic. The checker report listsCheckOther::checkZeroDivisionas active.Expected behavior
Cppcheck should report a division-by-zero diagnostic at line 3 because
x >= 0makes(x < 0)and thereforedivisorequal to zero.Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15059