From c262aeffdd22175153b37eb28eef622b7309b74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 26 Mar 2019 19:57:32 +0100 Subject: [PATCH] Fixed #9068 (crash on invalid code) --- lib/tokenize.cpp | 8 ++++++++ test/testgarbage.cpp | 1 + 2 files changed, 9 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f2bbbde06..41bea2189 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8993,6 +8993,14 @@ static const Token *findUnmatchedTernaryOp(const Token * const begin, const Toke void Tokenizer::findGarbageCode() const { + // initialization: = { + for (const Token *tok = tokens(); tok; tok = tok->next()) { + if (!Token::simpleMatch(tok, "= {")) + continue; + if (Token::simpleMatch(tok->linkAt(1), "} (")) + syntaxError(tok->linkAt(1)); + } + // Inside [] there can't be ; or various keywords for (const Token *tok = tokens(); tok; tok = tok->next()) { if (tok->str() != "[") diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 789cec1fa..ace4f0087 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -1656,6 +1656,7 @@ private: ASSERT_THROW(checkCode("void f(){x=0,return return''[]()}"), InternalError); ASSERT_THROW(checkCode("void f(){x='0'++'0'(return)[];}"), InternalError); // #9063 ASSERT_THROW(checkCode("void f() { x= 'x' > typedef name5 | ( , ;){ } (); }"), InternalError); // #9067 + ASSERT_THROW(checkCode("void f() { x= {}( ) ( 'x')[ ] (); }"), InternalError); // #9068 } void enumTrailingComma() {