From 0dc3cb6eba36954e63cd3b9ca74579f8af452d96 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 26 Apr 2022 17:25:56 +0200 Subject: [PATCH 1/2] Fix #11007 FP nullPointerRedundantCheck with static function pointer (#4051) --- lib/checknullpointer.cpp | 9 +++++++-- test/testnullpointer.cpp | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 19093d023..62ff03ba0 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -182,8 +182,13 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Set return false; // Dereferencing pointer.. - if (parent->isUnaryOp("*") && !addressOf) - return true; + if (parent->isUnaryOp("*")) { + // declaration of function pointer + if (tok->variable() && tok->variable()->nameToken() == tok) + return false; + if (!addressOf) + return true; + } // array access if (firstOperand && parent->str() == "[" && !addressOf) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index f5635b2c0..b2fdd2568 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -1137,6 +1137,15 @@ private: "}"); ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: f\n", errout.str()); + check("int* g();\n" // #11007 + "int* f() {\n" + " static int* (*fun)() = 0;\n" + " if (!fun)\n" + " fun = g;\n" + " return fun();\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // loops.. check("void f() {\n" " int *p = 0;\n" From e8a96932e1c751297560b0f150b659fc37b98330 Mon Sep 17 00:00:00 2001 From: Falital Date: Tue, 26 Apr 2022 17:39:39 +0200 Subject: [PATCH 2/2] Don't add suppressed errors to plist output (#4038) --- lib/cppcheck.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 8abec31c8..1e08162ee 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1542,7 +1542,9 @@ void CppCheck::reportErr(const ErrorMessage &msg) mErrorList.push_back(errmsg); mErrorLogger.reportErr(msg); - if (!mSettings.plistOutput.empty() && plistFile.is_open()) { + // check if plistOutput should be populated and the current output file is open and the error is not suppressed + if (!mSettings.plistOutput.empty() && plistFile.is_open() && !mSettings.nomsg.isSuppressed(errorMessage)) { + // add error to plist output file plistFile << ErrorLogger::plistData(msg); } }