Skip to content

Commit c59a00e

Browse files
Fix #13564 Crash in simplifyTypedefCpp() (#7234)
1 parent 8f42596 commit c59a00e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: lib/tokenize.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ void Tokenizer::simplifyTypedefCpp()
20162016
const bool isPointerTypeCall = !inOperator && Token::Match(tok2, "%name% ( )") && !pointers.empty();
20172017

20182018
// start substituting at the typedef name by replacing it with the type
2019-
const Token * const location = tok2;
2019+
const Token* location = tok2;
20202020
for (Token* tok3 = typeStart; tok3 && (tok3->str() != ";"); tok3 = tok3->next())
20212021
tok3->isSimplifiedTypedef(true);
20222022
if (isPointerTypeCall) {
@@ -2081,6 +2081,7 @@ void Tokenizer::simplifyTypedefCpp()
20812081
if (constTok && !functionPtr) {
20822082
tok2 = simplifyTypedefInsertToken(tok2, "const", location);
20832083
constTok->deleteThis();
2084+
location = constTok;
20842085
}
20852086
}
20862087

Diff for: test/testsimplifytypedef.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class TestSimplifyTypedef : public TestFixture {
223223
TEST_CASE(simplifyTypedef155);
224224
TEST_CASE(simplifyTypedef156);
225225
TEST_CASE(simplifyTypedef157);
226+
TEST_CASE(simplifyTypedef158);
226227

227228
TEST_CASE(simplifyTypedefFunction1);
228229
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@@ -3773,6 +3774,16 @@ class TestSimplifyTypedef : public TestFixture {
37733774
ASSERT_EQUALS(exp, tok(code));
37743775
}
37753776

3777+
void simplifyTypedef158() {
3778+
const char code[] = "void f() {\n"
3779+
" typedef const char* const triple[3];\n"
3780+
" static const triple data[] = { {\"a\" , \"b\" , \"c\" } };\n"
3781+
"}\n";
3782+
const char exp[] = "void f ( ) { static const char * const data [ ] [ 3 ] = { { \"a\" , \"b\" , \"c\" } } ; }";
3783+
const char cur[] = "void f ( ) { static const char * const const data [ ] [ 3 ] = { { \"a\" , \"b\" , \"c\" } } ; }";
3784+
TODO_ASSERT_EQUALS(exp, cur, tok(code));
3785+
}
3786+
37763787
void simplifyTypedefFunction1() {
37773788
{
37783789
const char code[] = "typedef void (*my_func)();\n"

0 commit comments

Comments
 (0)