Skip to content

Commit

Permalink
Fix #11644 Tokenizer: garbage code '(sizeof=)' (#6166)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Mar 22, 2024
1 parent 6e6b203 commit 7dfbb65
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8583,9 +8583,12 @@ void Tokenizer::findGarbageCode() const
bool match1 = Token::Match(tok, "%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|++|--|::|sizeof");
bool match2 = Token::Match(tok->next(), "{|if|else|while|do|for|return|switch|break");
if (isCPP()) {
match1 = match1 || Token::Match(tok, "::|throw|decltype|typeof");
match1 = match1 || Token::Match(tok, "throw|decltype|typeof");
match2 = match2 || Token::Match(tok->next(), "try|catch|namespace");
}
if (match1 && !tok->isIncDecOp()) {
match2 = match2 || Token::Match(tok->next(), "%assign%");
}
if (match1 && match2)
syntaxError(tok);
}
Expand Down
5 changes: 5 additions & 0 deletions test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class TestGarbage : public TestFixture {
TEST_CASE(garbageCode222); // #10763
TEST_CASE(garbageCode223); // #11639
TEST_CASE(garbageCode224);
TEST_CASE(garbageCode225);

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

Expand Down Expand Up @@ -1746,6 +1747,10 @@ class TestGarbage : public TestFixture {
checkCode("void f(){ auto* b = dynamic_cast<const }"); // don't crash
(void)errout_str(); // we are not interested in the output
}
void garbageCode225() {
ASSERT_THROW(checkCode("int n() { c * s0, 0 s0 = c(sizeof = ) }"), InternalError);
ASSERT_THROW(checkCode("int n() { c * s0, 0 s0 = c(sizeof |= ) }"), InternalError);
}

void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818
Expand Down
2 changes: 1 addition & 1 deletion test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6794,7 +6794,7 @@ class TestUnusedVar : public TestFixture {
" int a = 0;\n"
" do {\n"
" dostuff(a);\n"
" } while((a + = x) < 30);\n"
" } while((a += x) < 30);\n"
"}");
ASSERT_EQUALS("", errout_str());

Expand Down

0 comments on commit 7dfbb65

Please sign in to comment.