diff --git a/lib/executionpath.cpp b/lib/executionpath.cpp index 6a98bfe4e..836189c7d 100644 --- a/lib/executionpath.cpp +++ b/lib/executionpath.cpp @@ -427,7 +427,10 @@ static void checkExecutionPaths_(const Token *tok, std::list &c } // return/throw ends all execution paths - if (tok->str() == "return" || tok->str() == "throw") + if (tok->str() == "return" || + tok->str() == "throw" || + tok->str() == "continue" || + tok->str() == "break") { ExecutionPath::bailOut(checks); } diff --git a/test/testother.cpp b/test/testother.cpp index f63472588..e623fff83 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1057,6 +1057,17 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:12]: (error) Possible null pointer dereference: Q\n", errout.str()); + // Ticket #2052 (false positive for 'else continue;') + checkNullPointer("void f() {\n" + " for (int x = 0; x < 5; ++x) {" + " int *p = 0;\n" + " if (a(x)) p=b(x);\n" + " else continue;\n" + " *p = 0;\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // function pointer.. checkNullPointer("void foo()\n" "{\n"