Skip to content

Commit c262aef

Browse files
committed
Fixed cppcheck-opensource#9068 (crash on invalid code)
1 parent ce11778 commit c262aef

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎lib/tokenize.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8993,6 +8993,14 @@ static const Token *findUnmatchedTernaryOp(const Token * const begin, const Toke
89938993

89948994
void Tokenizer::findGarbageCode() const
89958995
{
8996+
// initialization: = {
8997+
for (const Token *tok = tokens(); tok; tok = tok->next()) {
8998+
if (!Token::simpleMatch(tok, "= {"))
8999+
continue;
9000+
if (Token::simpleMatch(tok->linkAt(1), "} ("))
9001+
syntaxError(tok->linkAt(1));
9002+
}
9003+
89969004
// Inside [] there can't be ; or various keywords
89979005
for (const Token *tok = tokens(); tok; tok = tok->next()) {
89989006
if (tok->str() != "[")

‎test/testgarbage.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,7 @@ class TestGarbage : public TestFixture {
16561656
ASSERT_THROW(checkCode("void f(){x=0,return return''[]()}"), InternalError);
16571657
ASSERT_THROW(checkCode("void f(){x='0'++'0'(return)[];}"), InternalError); // #9063
16581658
ASSERT_THROW(checkCode("void f() { x= 'x' > typedef name5 | ( , ;){ } (); }"), InternalError); // #9067
1659+
ASSERT_THROW(checkCode("void f() { x= {}( ) ( 'x')[ ] (); }"), InternalError); // #9068
16591660
}
16601661

16611662
void enumTrailingComma() {

0 commit comments

Comments
 (0)