When running using 2.18 or the latest code from 17-Oct-25, I get the following spurious warnings:
test.c:6:15: warning: Either the condition 'text' is redundant or there is possible null pointer dereference: text. [nullPointerRedundantCheck]
if (strcmp(text, "test"))
^
test.c:9:8: note: Assuming that condition 'text' is not redundant
if (text) free(text);
^
test.c:6:15: note: Null pointer dereference
if (strcmp(text, "test"))
If I remove the final "if (text)" condition, it no longer generates the warnings. I would not expect that redundant condition to cause warnings in the strcmp call at the beginning.
This didn't occur in 2.17, and at the moment, I'm forced to suppress that particular check.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14214
Maybe you can avoid the warning by adding --check-level=exhaustive to your command line.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have the following code:
When running using 2.18 or the latest code from 17-Oct-25, I get the following spurious warnings:
test.c:6:15: warning: Either the condition 'text' is redundant or there is possible null pointer dereference: text. [nullPointerRedundantCheck]
if (strcmp(text, "test"))
^
test.c:9:8: note: Assuming that condition 'text' is not redundant
if (text) free(text);
^
test.c:6:15: note: Null pointer dereference
if (strcmp(text, "test"))
If I remove the final "if (text)" condition, it no longer generates the warnings. I would not expect that redundant condition to cause warnings in the strcmp call at the beginning.
This didn't occur in 2.17, and at the moment, I'm forced to suppress that particular check.
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14214
Maybe you can avoid the warning by adding
--check-level=exhaustiveto your command line.Hi, thanks for the suggestion. That does remove the error, but unfortunately a trivial change re-introduces it:
Replacing the "printf" with "goto END" in the strcmp conditional causes the nullPointerRedundantCheck to occur even with --check-level=exhaustive
For the moment I will simply disable this warning.