diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 3d778312f..766c0243c 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -497,8 +497,8 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() continue; } - // abort function.. - if (Token::simpleMatch(tok2, ") ; }") && + // calling unknown function (abort/init).. + if (Token::simpleMatch(tok2, ") ;") && Token::Match(tok2->link()->tokAt(-2), "[;{}] %var% (")) { break; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index f3e684e57..1b12745ad 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -747,6 +747,16 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // ticket: #2300 - calling unknown function that may initialize the pointer + check("Fred *fred;\n" + "void a() {\n" + " if (!fred) {\n" + " initfred();\n" + " fred->x = 0;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } };