diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 0e7b4d91c..8a9f0edf7 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2569,6 +2569,13 @@ void CheckOther::nullPointerByCheckAndDeRef() break; } + // abort function.. + if (Token::Match(tok2->previous(), "[;{}] %var% (") && + Token::simpleMatch(tok2->next()->link(), ") ; }")) + { + break; + } + if (tok2->varId() == varid) { if (Token::Match(tok2->previous(), "[;{}=] %var% = 0 ;")) diff --git a/test/testother.cpp b/test/testother.cpp index 863903060..192c5de44 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1169,6 +1169,15 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkNullPointer("void foo(char *p) {\n" + " if (!p) {\n" + " abort();\n" + " }\n" + " *p = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void checkUninitVar(const char code[])