I'm on cppcheck 2.3. I apologize in advance if this is already fixed...it's not trivial for me to upgrade my environment.
Test program, a.cpp:
#include <cstdlib> template <typename... Args> void fatalError(int code, const char* fmt, Args&&... args) { exit(code); } int main(int argc, char* argv[]) { int* ptr = argc == 2 ? new int : nullptr; if (!ptr) { fatalError(1, "%s", argv[0]); /* fatalError(1, "%d", argc); // uncomment line to bypass false +ve */ } *ptr; return 0; }
cppcheck --enable=warning a.cpp results in a nullPointerRedundantCheck warning. Uncommenting the line results in no warnings.
At this point, I'm pretty confident that it's not my error. Thanks in advance for any help.
I can reproduce with cppcheck-2.3 and cppcheck-2.4. but it's fixed in cppcheck-2.5
no problem, thanks for reporting.
There is a variation involving namespaces that results in a false positive on 2.5.
#include <cstdlib> namespace ns { template <typename... Args> void fatalError(int code, const char* fmt, Args&&... args) { exit(code); } } int main(int argc, char* argv[]) { int* ptr = argc == 2 ? new int : nullptr; if (!ptr) { using namespace ns; fatalError(1, "%s", argv[0]); /* ns::fatalError(1, "%s", argv[0]); // uncomment line to bypass false +ve */ } *ptr; return 0; }
Log in to post a comment.
I'm on cppcheck 2.3. I apologize in advance if this is already fixed...it's not trivial for me to upgrade my environment.
Test program, a.cpp:
cppcheck --enable=warning a.cpp results in a nullPointerRedundantCheck warning. Uncommenting the line results in no warnings.
At this point, I'm pretty confident that it's not my error. Thanks in advance for any help.
Last edit: Mark Bourgeault 2021-08-27
I can reproduce with cppcheck-2.3 and cppcheck-2.4. but it's fixed in cppcheck-2.5
no problem, thanks for reporting.
There is a variation involving namespaces that results in a false positive on 2.5.