Skip to content

Commit 1cce204

Browse files
Fix #11393 FP danglingLifetime with pointer to pointer (danmar#7226)
1 parent df74fc0 commit 1cce204

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/checkautovariables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
648648
if (var && !var->isLocal() && !var->isArgument() && !(val.tokvalue && val.tokvalue->variable() && val.tokvalue->variable()->isStatic()) &&
649649
!isVariableChanged(nextTok,
650650
tok->scope()->bodyEnd,
651+
var->valueType() ? var->valueType()->pointer : 0,
651652
var->declarationId(),
652653
var->isGlobal(),
653654
*mSettings)) {

test/testautovariables.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,21 @@ class TestAutoVariables : public TestFixture {
990990
" int *ptr;\n"
991991
"};");
992992
ASSERT_EQUALS("", errout_str());
993+
994+
check("struct R {\n" // #11393
995+
" void pop() { p = nullptr; };\n"
996+
" int* p;\n"
997+
"};\n"
998+
"struct T {\n"
999+
" void f();\n"
1000+
" R* r;\n"
1001+
"};\n"
1002+
"void T::f() {\n"
1003+
" int i = 0;\n"
1004+
" r->p = &i;\n"
1005+
" r->pop();\n"
1006+
"}\n");
1007+
ASSERT_EQUALS("", errout_str());
9931008
}
9941009

9951010
void returnLocalVariable1() {

0 commit comments

Comments
 (0)