From 0e208eb52f8a59a74e44fd3c56e4fcfe7ba8e0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 20 Jul 2009 19:59:55 +0200 Subject: [PATCH] null pointer dereferencing: fixed another false positive (#485) --- src/checkother.cpp | 3 +++ test/testother.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/checkother.cpp b/src/checkother.cpp index a69b30cef..f566ce7fb 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -1051,6 +1051,9 @@ void CheckOther::nullPointer() --indentlevel2; } + else if (Token::Match(tok2, "%varid% =", varid1)) + break; + else if (tok2->str() == "if") { if (Token::Match(tok2, "if ( !| %varid% )", varid1)) diff --git a/test/testother.cpp b/test/testother.cpp index 75ae08ff7..8fe279913 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -488,6 +488,16 @@ private: " ;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // reassign struct.. + checkNullPointer("void foo(struct ABC *abc)\n" + "{\n" + " a = abc->a;\n" + " abc = abc->next;\n" + " if (!abc)\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void checkOldStylePointerCast(const char code[])