Fix #12141 debug: simplifyUsing: unmatched body end (#5620)

This commit is contained in:
chrchr-github 2024-01-05 14:11:41 +01:00 committed by GitHub
parent f9134a69d2
commit c7cd091a93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 1 deletions

View File

@ -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* const tok3 = insertTokens(tok2, mRangeTypeQualifiers);
Token *after = tok3; Token *after = tok3;

View File

@ -3044,6 +3044,7 @@ private:
TEST_CASE(deallocuse2); TEST_CASE(deallocuse2);
TEST_CASE(fclose_false_positive); // #9575 TEST_CASE(fclose_false_positive); // #9575
TEST_CASE(strcpy_false_negative); TEST_CASE(strcpy_false_negative);
TEST_CASE(doubleFree);
} }
void returnedValue() { // #9298 void returnedValue() { // #9298
@ -3089,6 +3090,15 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: buf\n", errout.str()); 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) REGISTER_TEST(TestLeakAutoVarStrcpy)

View File

@ -1608,6 +1608,31 @@ private:
ASSERT_EQUALS(expected, tok(code)); ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str()); 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() { void simplifyTypedef45() {