diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 410261836..ead83c472 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1307,6 +1307,8 @@ private: dereference(foundError, checks, &tok); else if (Token::Match(tok.previous(), "return %var% [ %any% ]")) dereference(foundError, checks, &tok); + else if (Token::Match(&tok, "%var% (")) + dereference(foundError, checks, &tok); else bailOutVar(checks, tok.varId()); } diff --git a/test/testother.cpp b/test/testother.cpp index 8a4674d4b..1b7fd94ed 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -990,6 +990,15 @@ private: " int sz = sizeof((*(struct dummy *)0).x);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // function pointer.. + checkNullPointer("void foo()\n" + "{\n" + " void (*f)();\n" + " f = 0;\n" + " f();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: f\n", errout.str()); } void nullpointer7()