Skip to content

Commit 7dfbb65

Browse files
Fix #11644 Tokenizer: garbage code '(sizeof=)' (#6166)
1 parent 6e6b203 commit 7dfbb65

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/tokenize.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8583,9 +8583,12 @@ void Tokenizer::findGarbageCode() const
85838583
bool match1 = Token::Match(tok, "%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|++|--|::|sizeof");
85848584
bool match2 = Token::Match(tok->next(), "{|if|else|while|do|for|return|switch|break");
85858585
if (isCPP()) {
8586-
match1 = match1 || Token::Match(tok, "::|throw|decltype|typeof");
8586+
match1 = match1 || Token::Match(tok, "throw|decltype|typeof");
85878587
match2 = match2 || Token::Match(tok->next(), "try|catch|namespace");
85888588
}
8589+
if (match1 && !tok->isIncDecOp()) {
8590+
match2 = match2 || Token::Match(tok->next(), "%assign%");
8591+
}
85898592
if (match1 && match2)
85908593
syntaxError(tok);
85918594
}

test/testgarbage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class TestGarbage : public TestFixture {
253253
TEST_CASE(garbageCode222); // #10763
254254
TEST_CASE(garbageCode223); // #11639
255255
TEST_CASE(garbageCode224);
256+
TEST_CASE(garbageCode225);
256257

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

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

17501755
void syntaxErrorFirstToken() {
17511756
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818

test/testunusedvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6794,7 +6794,7 @@ class TestUnusedVar : public TestFixture {
67946794
" int a = 0;\n"
67956795
" do {\n"
67966796
" dostuff(a);\n"
6797-
" } while((a + = x) < 30);\n"
6797+
" } while((a += x) < 30);\n"
67986798
"}");
67996799
ASSERT_EQUALS("", errout_str());
68006800

0 commit comments

Comments
 (0)