Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when destruction of a temporary object changes a global value to zero before a division.
Affected tool
Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev
Affected checker
Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond)
Minimal reproducer
int global; struct Value { Value() { global = 1; } ~Value() { global = 0; } }; int test() { Value{}; return 1 / global; }
Reproduction command
cppcheck --version cppcheck --enable=warning --std=c++17 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-temporary-destructor.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 10 because the temporary's destructor assigns zero to global before the division.
global
Added here: https://trac.cppcheck.net/ticket/11563
Log in to post a comment.
Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when destruction of a temporary object changes a global value to zero before a division.
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 10 because the temporary's destructor assigns zero to
globalbefore the division.Added here: https://trac.cppcheck.net/ticket/11563