Skip to content

Commit

Permalink
Fix #12141 debug: simplifyUsing: unmatched body end (#5620)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 5, 2024
1 parent f9134a6 commit c7cd091
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,14 @@ namespace {
}
}

Token* const tok2 = insertTokens(tok, mRangeType);
// don't add class|struct|union in inheritance list
auto rangeType = mRangeType;
if (Token::Match(tok->previous(), "public|private|protected")) {
while (Token::Match(rangeType.first, "const|class|struct|union"))
rangeType.first = rangeType.first->next();
}

Token* const tok2 = insertTokens(tok, rangeType);
Token* const tok3 = insertTokens(tok2, mRangeTypeQualifiers);

Token *after = tok3;
Expand Down
10 changes: 10 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3044,6 +3044,7 @@ class TestLeakAutoVarStrcpy : public TestFixture {
TEST_CASE(deallocuse2);
TEST_CASE(fclose_false_positive); // #9575
TEST_CASE(strcpy_false_negative);
TEST_CASE(doubleFree);
}

void returnedValue() { // #9298
Expand Down Expand Up @@ -3089,6 +3090,15 @@ class TestLeakAutoVarStrcpy : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: buf\n", errout.str());
}

void doubleFree() {
check("void f(char* p) {\n"
" free(p);\n"
" printf(\"%s\", p = strdup(\"abc\"));\n"
" free(p);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};

REGISTER_TEST(TestLeakAutoVarStrcpy)
Expand Down
25 changes: 25 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,31 @@ class TestSimplifyTypedef : public TestFixture {
ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str());
}

{
const char code[] = "struct B {};\n" // #12141
"typedef struct B B;\n"
"namespace N {\n"
" struct D : public B {};\n"
"}\n";

const char expected[] = "struct B { } ; namespace N { struct D : public B { } ; }";
ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str());
}

{
const char code[] = "struct B {};\n"
"typedef const struct B CB;\n"
"namespace N {\n"
" struct D : public CB {};\n"
"}\n"
"CB cb;\n";

const char expected[] = "struct B { } ; namespace N { struct D : public B { } ; } const struct B cb ;";
ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str());
}
}

void simplifyTypedef45() {
Expand Down

0 comments on commit c7cd091

Please sign in to comment.