diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index eb9c38f71..cb4c9702b 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -608,7 +608,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() } } - if (Token::Match(tok2, "goto|return|continue|break|throw|if")) + if (Token::Match(tok2, "goto|return|continue|break|throw|if|switch")) { if (Token::Match(tok2, "return * %varid%", varid)) nullPointerError(tok2, tok->strAt(3)); diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 81263f9ce..1742fab5a 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -868,6 +868,19 @@ private: " fred->a();\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #2493 - switch + check("void f(Fred *fred) {\n" + " if (fred == NULL) {\n" + " x = 0;\n" + " }\n" + " switch (x) {\n" + " case 1:\n" + " fred->a();\n" + " break;\n" + " };\n" + "}"); + ASSERT_EQUALS("", errout.str()); } // Test CheckNullPointer::nullConstantDereference