diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 417c72472..fe214960d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4503,7 +4503,10 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition) tokAfterCondition->previous()->insertToken("{"); Token * tokOpenBrace = tokAfterCondition->previous(); Token * tokEnd = tokAfterCondition->linkAt(1)->linkAt(2)->linkAt(1); - + if (!tokEnd) { + syntaxError(tokAfterCondition); + return nullptr; + } tokEnd->insertToken("}"); Token * tokCloseBrace = tokEnd->next(); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 45c6a6324..faea6c2b7 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -95,6 +95,7 @@ private: TEST_CASE(garbageCode54); // #6722 TEST_CASE(garbageCode55); // #6724 TEST_CASE(garbageCode56); // #6713 + TEST_CASE(garbageCode57); // #6733 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -540,6 +541,10 @@ private: checkCode("void foo() { int a = 0; int b = ???; }"); } + void garbageCode57() { // #6731 + ASSERT_THROW(checkCode("{ } if () try { } catch (...) B::~B { }"), InternalError); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"