diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index dbfa55553..44f75242f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7530,6 +7530,8 @@ void Tokenizer::simplifyEnum() for (; tok1 && tok1 != end; tok1 = tok1->next()) { if (tok1->str() == "(") { tok1 = tok1->link(); + if (!tok1) + syntaxError(nullptr); // #6909 continue; } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 58c45ac20..a1778283a 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -151,6 +151,7 @@ private: TEST_CASE(garbageCode109); TEST_CASE(garbageCode110); TEST_CASE(garbageCode111); + TEST_CASE(garbageCode112); TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -849,6 +850,10 @@ private: ASSERT_THROW(checkCode("enum { FOO = 1( ,) } {{ FOO }} ;"), InternalError); } + void garbageCode112() { // #6909 + ASSERT_THROW(checkCode("enum { FOO = ( , ) } {{ }}>> enum { FOO< = ( ) } { { } } ;"), InternalError); + } + void garbageValueFlow() {