Hi, I found a false positive in Cppcheck 2.21.0 when a helper either calls a noreturn function or returns zero.
Affected tool
Cppcheck 2.21.0
Affected checker
Cppcheck zerodiv
Minimal reproducer
void stop(void) __attribute__((noreturn)); int zero_or_stop(int condition) { if (condition) stop(); return 0; } int unreachable_division(int condition) { int zero = 0; if (zero_or_stop(condition)) return 1 / zero; return 0; }
Reproduction command
cppcheck --version cppcheck --enable=warning --std=c11 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fp-noreturn-summary.c
Current behavior
Cppcheck reports cppcheck-zerodiv-fp-noreturn-summary.c:12:14: [zerodiv] Division by zero.
cppcheck-zerodiv-fp-noreturn-summary.c:12:14: [zerodiv] Division by zero.
Expected behavior
Cppcheck should not report zerodiv. zero_or_stop either does not return or returns zero, so the branch containing the division is unreachable.
zerodiv
zero_or_stop
Looks like an instance of https://trac.cppcheck.net/ticket/14969 There already is a condition attached to the error message.
Log in to post a comment.
Hi, I found a false positive in Cppcheck 2.21.0 when a helper either calls a noreturn function or returns zero.
Affected tool
Cppcheck 2.21.0Affected checker
Cppcheck zerodivMinimal reproducer
Reproduction command
Current behavior
Cppcheck reports
cppcheck-zerodiv-fp-noreturn-summary.c:12:14: [zerodiv] Division by zero.Expected behavior
Cppcheck should not report
zerodiv.zero_or_stopeither does not return or returns zero, so the branch containing the division is unreachable.Looks like an instance of https://trac.cppcheck.net/ticket/14969
There already is a condition attached to the error message.