Skip to content

Commit cc684dd

Browse files
Fix #13051 FP unreadVariable when nulling deleted pointer (regression) (#6949)
1 parent f122da3 commit cc684dd

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Diff for: lib/checkmemoryleak.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
8787
while (Token::Match(typeTok, "%name% :: %name%"))
8888
typeTok = typeTok->tokAt(2);
8989
const Scope* classScope = nullptr;
90-
if (typeTok->type() && typeTok->type()->isClassType()) {
90+
if (typeTok->type() && (typeTok->type()->isClassType() || typeTok->type()->isStructType() || typeTok->type()->isUnionType())) {
9191
classScope = typeTok->type()->classScope;
9292
} else if (typeTok->function() && typeTok->function()->isConstructor()) {
9393
classScope = typeTok->function()->nestedIn;

Diff for: lib/symboldatabase.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -5716,6 +5716,8 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen
57165716
const Function *func = it->second;
57175717
if (ref == Reference::LValue && func->hasRvalRefQualifier())
57185718
continue;
5719+
if (func->isDestructor() && !Token::simpleMatch(tok->tokAt(-1), "~"))
5720+
continue;
57195721
if (!isCall || args == func->argCount() ||
57205722
(func->isVariadic() && args >= (func->minArgCount() - 1)) ||
57215723
(args < func->argCount() && args >= func->minArgCount())) {

Diff for: test/testsymboldatabase.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ class TestSymbolDatabase : public TestFixture {
520520
TEST_CASE(findFunction54);
521521
TEST_CASE(findFunction55); // #13004
522522
TEST_CASE(findFunction56);
523+
TEST_CASE(findFunction57);
523524
TEST_CASE(findFunctionRef1);
524525
TEST_CASE(findFunctionContainer);
525526
TEST_CASE(findFunctionExternC);
@@ -8349,6 +8350,30 @@ class TestSymbolDatabase : public TestFixture {
83498350
ASSERT_EQUALS(f->function()->tokenDef->linenr(), 1);
83508351
}
83518352

8353+
void findFunction57() { // #13051
8354+
GET_SYMBOL_DB("struct S {\n"
8355+
" ~S();\n"
8356+
" void f();\n"
8357+
"};\n"
8358+
"struct T {\n"
8359+
" T();\n"
8360+
"};\n"
8361+
"void S::f() {\n"
8362+
" auto s1 = new S;\n"
8363+
" auto s2 = new S();\n"
8364+
" auto t = new T();\n"
8365+
"}\n");
8366+
const Token* S = Token::findsimplematch(tokenizer.tokens(), "S ;");
8367+
ASSERT(S && S->type());
8368+
ASSERT_EQUALS(S->type()->classDef->linenr(), 1);
8369+
S = Token::findsimplematch(S, "S (");
8370+
ASSERT(S && S->type());
8371+
ASSERT_EQUALS(S->type()->classDef->linenr(), 1);
8372+
const Token* T = Token::findsimplematch(S, "T (");
8373+
ASSERT(T && T->function());
8374+
ASSERT_EQUALS(T->function()->tokenDef->linenr(), 6);
8375+
}
8376+
83528377
void findFunctionRef1() {
83538378
GET_SYMBOL_DB("struct X {\n"
83548379
" const std::vector<int> getInts() const & { return mInts; }\n"

0 commit comments

Comments
 (0)