Skip to content

Commit

Permalink
Fix #13368 Crash in simplifyTypedefCpp() (danmar#7061)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 3, 2024
1 parent cbc1661 commit 0cbf73c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2080,8 +2080,8 @@ void Tokenizer::simplifyTypedefCpp()
// cppcheck-suppress useStlAlgorithm
tok2 = simplifyTypedefInsertToken(tok2, p, location);
if (constTok) {
constTok->deleteThis();
tok2 = simplifyTypedefInsertToken(tok2, "const", location);
constTok->deleteThis();
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class TestSimplifyTypedef : public TestFixture {

TEST_CASE(simplifyTypedefTokenColumn1);
TEST_CASE(simplifyTypedefTokenColumn2);
TEST_CASE(simplifyTypedefTokenColumn3);

TEST_CASE(typedefInfo1);

Expand Down Expand Up @@ -4493,6 +4494,14 @@ class TestSimplifyTypedef : public TestFixture {
ASSERT_EQUALS(5, type->column());
}

void simplifyTypedefTokenColumn3() { // #13368
const char code[] = "typedef struct S_ {} S;\n"
"typedef S* P;\n"
"void f(const P p);\n";
ASSERT_EQUALS("struct S_ { } ; void f ( struct S_ * const p ) ;", // don't crash
tok(code));
}

void typedefInfo1() {
const std::string xml = dumpTypedefInfo("typedef int A;\nA x;");
ASSERT_EQUALS(" <typedef-info>\n"
Expand Down

0 comments on commit 0cbf73c

Please sign in to comment.