Skip to content

Commit 0cbf73c

Browse files
Fix #13368 Crash in simplifyTypedefCpp() (danmar#7061)
1 parent cbc1661 commit 0cbf73c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/tokenize.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2080,8 +2080,8 @@ void Tokenizer::simplifyTypedefCpp()
20802080
// cppcheck-suppress useStlAlgorithm
20812081
tok2 = simplifyTypedefInsertToken(tok2, p, location);
20822082
if (constTok) {
2083-
constTok->deleteThis();
20842083
tok2 = simplifyTypedefInsertToken(tok2, "const", location);
2084+
constTok->deleteThis();
20852085
}
20862086
}
20872087

test/testsimplifytypedef.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class TestSimplifyTypedef : public TestFixture {
245245

246246
TEST_CASE(simplifyTypedefTokenColumn1);
247247
TEST_CASE(simplifyTypedefTokenColumn2);
248+
TEST_CASE(simplifyTypedefTokenColumn3);
248249

249250
TEST_CASE(typedefInfo1);
250251

@@ -4493,6 +4494,14 @@ class TestSimplifyTypedef : public TestFixture {
44934494
ASSERT_EQUALS(5, type->column());
44944495
}
44954496

4497+
void simplifyTypedefTokenColumn3() { // #13368
4498+
const char code[] = "typedef struct S_ {} S;\n"
4499+
"typedef S* P;\n"
4500+
"void f(const P p);\n";
4501+
ASSERT_EQUALS("struct S_ { } ; void f ( struct S_ * const p ) ;", // don't crash
4502+
tok(code));
4503+
}
4504+
44964505
void typedefInfo1() {
44974506
const std::string xml = dumpTypedefInfo("typedef int A;\nA x;");
44984507
ASSERT_EQUALS(" <typedef-info>\n"

0 commit comments

Comments
 (0)