From 893f7fa3479a3f84556851f703e05d3d56c3c246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 26 Oct 2010 17:40:30 +0200 Subject: [PATCH] Fixed #2130 (Invalid possible NULL pointer dereference, etc.) --- lib/checkother.cpp | 7 +++++++ test/testother.cpp | 9 +++++++++ 2 files changed, 16 insertions(+) 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[])