Skip to content

Commit 43e6e6e

Browse files
Fix #12823 Crash in isVariableChanged() with unknown macro (#6494)
1 parent 3e54980 commit 43e6e6e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/tokenize.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -8706,6 +8706,8 @@ void Tokenizer::findGarbageCode() const
87068706
if (!Token::Match(tok->next(), "%name%|*|~"))
87078707
syntaxError(tok, tok->strAt(-1) + " " + tok->str() + " " + tok->strAt(1));
87088708
}
8709+
if (Token::Match(tok, "[{,] . %name%") && !Token::Match(tok->tokAt(3), "[.=[{]"))
8710+
syntaxError(tok->next());
87098711
if (Token::Match(tok, "[!|+-/%^~] )|]"))
87108712
syntaxError(tok);
87118713
if (Token::Match(tok, "==|!=|<=|>= %comp%") && tok->strAt(-1) != "operator")
@@ -8760,6 +8762,8 @@ void Tokenizer::findGarbageCode() const
87608762
if (!tok2->next() || tok2->isControlFlowKeyword() || Token::Match(tok2, "typedef|static|."))
87618763
syntaxError(tok);
87628764
if (Token::Match(tok2, "%name% %name%") && tok2->str() == tok2->strAt(1)) {
8765+
if (Token::simpleMatch(tok2->tokAt(2), ";"))
8766+
continue;
87638767
if (tok2->isStandardType() && tok2->str() == "long")
87648768
continue;
87658769
if (Token::Match(tok2->tokAt(-1), "enum|struct|union") || (isCPP() && Token::Match(tok2->tokAt(-1), "class|::")))

test/testsimplifytypedef.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class TestSimplifyTypedef : public TestFixture {
218218
TEST_CASE(simplifyTypedef151);
219219
TEST_CASE(simplifyTypedef152);
220220
TEST_CASE(simplifyTypedef153);
221+
TEST_CASE(simplifyTypedef154);
221222

222223
TEST_CASE(simplifyTypedefFunction1);
223224
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@@ -3605,6 +3606,14 @@ class TestSimplifyTypedef : public TestFixture {
36053606
ASSERT_EQUALS(exp, tok(code));
36063607
}
36073608

3609+
void simplifyTypedef154() {
3610+
const char code[] = "typedef int T;\n"
3611+
"typedef T T;\n"
3612+
"T t = 0;\n";
3613+
const char exp[] = "int t ; t = 0 ;";
3614+
ASSERT_EQUALS(exp, tok(code));
3615+
}
3616+
36083617
void simplifyTypedefFunction1() {
36093618
{
36103619
const char code[] = "typedef void (*my_func)();\n"

test/testtokenize.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -7108,6 +7108,8 @@ class TestTokenizer : public TestFixture {
71087108
// Ticket #9664
71097109
ASSERT_NO_THROW(tokenizeAndStringify("S s = { .x { 2 }, .y[0] { 3 } };"));
71107110

7111+
ASSERT_THROW_INTERNAL(tokenizeAndStringify("f(0, .x());"), SYNTAX); // #12823
7112+
71117113
// Ticket #11134
71127114
ASSERT_NO_THROW(tokenizeAndStringify("struct my_struct { int x; }; "
71137115
"std::string s; "

0 commit comments

Comments
 (0)