diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 8b1034df5..19d73dba3 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2543,6 +2543,8 @@ void CheckOther::nullPointerByCheckAndDeRef() { bool null = true; const unsigned int varid(tok->tokAt(3)->varId()); + if (varid == 0) + continue; unsigned int indentlevel = 1; for (const Token *tok2 = tok->tokAt(6); tok2; tok2 = tok2->next()) { diff --git a/test/testother.cpp b/test/testother.cpp index a8db87a25..bb1f845f4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1197,6 +1197,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkNullPointer("void foo() {\n" + " if (!p) {\n" + " switch (x) { }\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void checkUninitVar(const char code[])