Skip to content

Commit 0fed6f0

Browse files
IOBYTEdanmar
authored andcommitted
fix clang testsuite crash (cppcheck-opensource#2341)
1 parent 81fff2e commit 0fed6f0

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10890,6 +10890,8 @@ void Tokenizer::simplifyOperatorName()
1089010890
op += par->strAt(1);
1089110891
par = par->tokAt(2);
1089210892
done = true;
10893+
} else if (par->str() != "(") {
10894+
syntaxError(par);
1089310895
}
1089410896
}
1089510897

test/testgarbage.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class TestGarbage : public TestFixture {
237237
TEST_CASE(garbageCode203); // #8972
238238
TEST_CASE(garbageCode204);
239239
TEST_CASE(garbageCode205);
240+
TEST_CASE(garbageCode206);
240241

241242
TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1
242243

@@ -1625,6 +1626,15 @@ class TestGarbage : public TestFixture {
16251626
"}"); // don't crash
16261627
}
16271628

1629+
void garbageCode206() {
1630+
{
1631+
ASSERT_EQUALS("[test.cpp:1] syntax error", getSyntaxError("void foo() { for (auto operator new : int); }"));
1632+
}
1633+
{
1634+
ASSERT_EQUALS("[test.cpp:1] syntax error", getSyntaxError("void foo() { for (a operator== :) }"));
1635+
}
1636+
}
1637+
16281638
void syntaxErrorFirstToken() {
16291639
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818
16301640
ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858

0 commit comments

Comments
 (0)