Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12823 Crash in isVariableChanged() with unknown macro #6494

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading