Skip to content

Commit 9433184

Browse files
Fix #14126 crash in Tokenizer::simplifyCPPAttribute() (#7862)
1 parent d9049eb commit 9433184

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/tokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9543,6 +9543,8 @@ void Tokenizer::simplifyCPPAttribute()
95439543
Token* head = skipCPPOrAlignAttribute(tok)->next();
95449544
while (isCPPAttribute(head) || isAlignAttribute(head))
95459545
head = skipCPPOrAlignAttribute(head)->next();
9546+
if (!head)
9547+
syntaxError(tok);
95469548
head->isAttributeMaybeUnused(true);
95479549
} else if (Token::findsimplematch(tok->tokAt(2), "unused", tok->link())) {
95489550
Token* head = skipCPPOrAlignAttribute(tok)->next();

test/testgarbage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class TestGarbage : public TestFixture {
257257
TEST_CASE(garbageCode226);
258258
TEST_CASE(garbageCode227);
259259
TEST_CASE(garbageCode228);
260+
TEST_CASE(garbageCode229);
260261

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

@@ -1768,6 +1769,10 @@ class TestGarbage : public TestFixture {
17681769
ASSERT_NO_THROW(checkCode("void f() { enum { A = [=]() mutable { return 0; }() }; }"));
17691770
ASSERT_NO_THROW(checkCode("enum { A = [=](void) mutable -> int { return 0; }() };"));
17701771
}
1772+
void garbageCode229() { // #14126
1773+
ASSERT_THROW_INTERNAL(checkCode("void f() {} [[maybe_unused]]"), SYNTAX);
1774+
}
1775+
17711776

17721777
void syntaxErrorFirstToken() {
17731778
ASSERT_THROW_INTERNAL(checkCode("&operator(){[]};"), SYNTAX); // #7818

0 commit comments

Comments
 (0)