From 7dfbb656fecc5263d1feea65171fb05f76d57aa5 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 22 Mar 2024 07:20:54 +0100 Subject: [PATCH] Fix #11644 Tokenizer: garbage code '(sizeof=)' (#6166) --- lib/tokenize.cpp | 5 ++++- test/testgarbage.cpp | 5 +++++ test/testunusedvar.cpp | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 08e053a840a..2dae34a355b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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); } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index f52ba217473..acb46bfe609 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -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 @@ -1746,6 +1747,10 @@ class TestGarbage : public TestFixture { checkCode("void f(){ auto* b = dynamic_cast