Hi, I found a false negative in Cppcheck 2.21.0 when a lambda captures a known zero value used as the divisor.
Affected checker
Cppcheck zerodiv
Minimal reproducer
int divide_by_lambda_capture() { int value = 0; return [=] { return 1 / value; }(); }
Reproduction command
cppcheck --version cppcheck --enable=warning --std=c++11 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-zerodiv-fn-lambda-capture.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 zerodiv at line 3 because the lambda captures value after it is initialized to zero.
value
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14996
Log in to post a comment.
Hi, I found a false negative in Cppcheck 2.21.0 when a lambda captures a known zero value used as the divisor.
Affected checker
Cppcheck zerodivMinimal reproducer
Reproduction command
Current behavior
Cppcheck produces neither a
zerodivnor azerodivconddiagnostic. The checker report listsCheckOther::checkZeroDivisionas active.Expected behavior
Cppcheck should report
zerodivat line 3 because the lambda capturesvalueafter it is initialized to zero.Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14996