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[])