Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when a helper writes zero through a pointer before the pointed-to value is used as a divisor.
Affected tool
Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev
Affected checker
Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond)
Minimal reproducer
void set_zero(int *value) { *value = 0; } int test() { int value; set_zero(&value); return 1 / value; }
Reproduction command
cppcheck --version cppcheck --enable=warning --std=c++17 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-out-parameter.cpp
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 line 8 because set_zero(&value) stores zero in value before the division.
set_zero(&value)
value
Example added here: https://trac.cppcheck.net/ticket/14239
Log in to post a comment.
Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when a helper writes zero through a pointer before the pointed-to value is used as a divisor.
Affected tool
Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 devAffected 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 line 8 because
set_zero(&value)stores zero invaluebefore the division.Example added here: https://trac.cppcheck.net/ticket/14239