Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when a constant argument makes a division inside a function-template instantiation divide by zero.
Affected tool
Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev
Affected checker
Cppcheck CheckOther::checkZeroDivision (zerodiv / zerodivcond)
Minimal reproducer
bool unknown(); template <class T> void divide(T value) { if (unknown()) value = 1 / (value - 5); } void test() { divide<int>(5); }
Reproduction command
cppcheck --version cppcheck --enable=warning --std=c++17 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-template-unknown-branch.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 6 because the instantiation receives value == 5, making value - 5 equal to zero.
value == 5
value - 5
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15051
Log in to post a comment.
Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when a constant argument makes a division inside a function-template instantiation divide by zero.
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 6 because the instantiation receives
value == 5, makingvalue - 5equal to zero.Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15051