diff --git a/lib/reverseanalyzer.cpp b/lib/reverseanalyzer.cpp index a6a86f63e..31deda58d 100644 --- a/lib/reverseanalyzer.cpp +++ b/lib/reverseanalyzer.cpp @@ -124,6 +124,8 @@ struct ReverseTraversal { } if (Token::Match(tok, "return|break|continue")) break; + if (Token::Match(tok, "%name% :")) + break; // Evaluate LHS of assignment before RHS if (Token* assignTok = assignExpr(tok)) { Token* assignTop = assignTok; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 94d772911..8a3738fe9 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -106,6 +106,7 @@ private: TEST_CASE(nullpointer63); TEST_CASE(nullpointer64); TEST_CASE(nullpointer65); // #9980 + TEST_CASE(nullpointer66); // #10024 TEST_CASE(nullpointer_addressOf); // address of TEST_CASE(nullpointerSwitch); // #2626 TEST_CASE(nullpointer_cast); // #4692 @@ -2032,6 +2033,23 @@ private: ASSERT_EQUALS("", errout.str()); } + void nullpointer66() { + check("int f() {\n" + " int ret = 0;\n" + " int *v = nullptr;\n" + " if (!MyAlloc(&v)) {\n" + " ret = -1;\n" + " goto done;\n" + " }\n" + " DoSomething(*v);\n" + "done:\n" + " if (v)\n" + " MyFree(&v);\n" + " return ret;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void nullpointer_addressOf() { // address of check("void f() {\n" " struct X *x = 0;\n"