Skip to content

Commit

Permalink
Fix #12823 Crash in isVariableChanged() with unknown macro (danmar#6494)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jun 8, 2024
1 parent 3e54980 commit 43e6e6e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8706,6 +8706,8 @@ void Tokenizer::findGarbageCode() const
if (!Token::Match(tok->next(), "%name%|*|~"))
syntaxError(tok, tok->strAt(-1) + " " + tok->str() + " " + tok->strAt(1));
}
if (Token::Match(tok, "[{,] . %name%") && !Token::Match(tok->tokAt(3), "[.=[{]"))
syntaxError(tok->next());
if (Token::Match(tok, "[!|+-/%^~] )|]"))
syntaxError(tok);
if (Token::Match(tok, "==|!=|<=|>= %comp%") && tok->strAt(-1) != "operator")
Expand Down Expand Up @@ -8760,6 +8762,8 @@ void Tokenizer::findGarbageCode() const
if (!tok2->next() || tok2->isControlFlowKeyword() || Token::Match(tok2, "typedef|static|."))
syntaxError(tok);
if (Token::Match(tok2, "%name% %name%") && tok2->str() == tok2->strAt(1)) {
if (Token::simpleMatch(tok2->tokAt(2), ";"))
continue;
if (tok2->isStandardType() && tok2->str() == "long")
continue;
if (Token::Match(tok2->tokAt(-1), "enum|struct|union") || (isCPP() && Token::Match(tok2->tokAt(-1), "class|::")))
Expand Down
9 changes: 9 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class TestSimplifyTypedef : public TestFixture {
TEST_CASE(simplifyTypedef151);
TEST_CASE(simplifyTypedef152);
TEST_CASE(simplifyTypedef153);
TEST_CASE(simplifyTypedef154);

TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
Expand Down Expand Up @@ -3605,6 +3606,14 @@ class TestSimplifyTypedef : public TestFixture {
ASSERT_EQUALS(exp, tok(code));
}

void simplifyTypedef154() {
const char code[] = "typedef int T;\n"
"typedef T T;\n"
"T t = 0;\n";
const char exp[] = "int t ; t = 0 ;";
ASSERT_EQUALS(exp, tok(code));
}

void simplifyTypedefFunction1() {
{
const char code[] = "typedef void (*my_func)();\n"
Expand Down
2 changes: 2 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7108,6 +7108,8 @@ class TestTokenizer : public TestFixture {
// Ticket #9664
ASSERT_NO_THROW(tokenizeAndStringify("S s = { .x { 2 }, .y[0] { 3 } };"));

ASSERT_THROW_INTERNAL(tokenizeAndStringify("f(0, .x());"), SYNTAX); // #12823

// Ticket #11134
ASSERT_NO_THROW(tokenizeAndStringify("struct my_struct { int x; }; "
"std::string s; "
Expand Down

0 comments on commit 43e6e6e

Please sign in to comment.