diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c21559147..f3de3ab31 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4500,7 +4500,7 @@ Token *Tokenizer::simplifyAddBracesPair(Token *tok, bool commandWithCondition) tokAfterCondition=tokCondition->link(); else tokAfterCondition=nullptr; - if (!tokAfterCondition) { + if (!tokAfterCondition || tokAfterCondition->strAt(1) == "]") { // Bad condition syntaxError(tok); return nullptr; diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index fba9c56f1..7773852c3 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -142,6 +142,7 @@ private: TEST_CASE(garbageCode100); TEST_CASE(garbageCode101); // #6835 TEST_CASE(garbageCode102); // #6846 + TEST_CASE(garbageCode103); // #6824 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -804,6 +805,10 @@ private: checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }"); } + void garbageCode103() { // #6824 + ASSERT_THROW(checkCode("a f(r) int * r; { { int s[2]; [f(s); if () ] } }"), InternalError); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"