Hi, I found a false positive in Cppcheck 2.21.0 when equivalent pointer expressions constrain an aliased divisor to be nonzero.
Affected tool
Cppcheck 2.21.0
Affected checker
Cppcheck zerodiv
Minimal reproducer
int divide_after_alias_check(void *data) { int *value = (int *)data; *value = 0; if (*(int *)data == 0) return 0; return 1 / *value; }
Reproduction command
cppcheck --version cppcheck --enable=warning --std=c11 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fp-alias-constraint.c
Current behavior
Cppcheck reports cppcheck-zerodiv-fp-alias-constraint.c:6:12: [zerodiv] Division by zero.
cppcheck-zerodiv-fp-alias-constraint.c:6:12: [zerodiv] Division by zero.
Expected behavior
Cppcheck should not report zerodiv. The final return is reached only when *(int *)data != 0, and value points to that same object.
zerodiv
*(int *)data != 0
value
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15003
Log in to post a comment.
Hi, I found a false positive in Cppcheck 2.21.0 when equivalent pointer expressions constrain an aliased divisor to be nonzero.
Affected tool
Cppcheck 2.21.0Affected checker
Cppcheck zerodivMinimal reproducer
Reproduction command
Current behavior
Cppcheck reports
cppcheck-zerodiv-fp-alias-constraint.c:6:12: [zerodiv] Division by zero.Expected behavior
Cppcheck should not report
zerodiv. The final return is reached only when*(int *)data != 0, andvaluepoints to that same object.Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15003