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"