diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index bb9ce5204..afe38cd38 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -981,6 +981,8 @@ static Token * createAstAtToken(Token *tok, bool cpp) compileExpression(tok2, state2); Token * const semicolon2 = tok2; + if (!semicolon2) + return nullptr; // invalid code #7235 tok2 = tok2->next(); AST_state state3(cpp); compileExpression(tok2, state3); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index da450e4c6..10a760b54 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -213,6 +213,7 @@ private: TEST_CASE(garbageCode162); // #7208 TEST_CASE(garbageCode163); // #7228 TEST_CASE(garbageCode164); // #7234 + TEST_CASE(garbageCode165); // #7235 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); @@ -1405,6 +1406,10 @@ private: ASSERT_THROW(checkCode("class d{k p;}(){d::d():B<()}", false), InternalError); } + void garbageCode165() { + //7235 + checkCode("for(;..)", false); + } }; REGISTER_TEST(TestGarbage)