From 5c14c52bf24b8d0904f428dee647da966a39d33e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:42:41 +0100 Subject: [PATCH 1/2] Update testautovariables.cpp --- test/testautovariables.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 3d4803cbbcb..f8aefd059f0 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -990,6 +990,21 @@ class TestAutoVariables : public TestFixture { " int *ptr;\n" "};"); ASSERT_EQUALS("", errout_str()); + + check("struct R {\n" // #11393 + " void pop() { p = nullptr; };\n" + " int* p;\n" + "};\n" + "struct T {\n" + " void f();\n" + " R* r;\n" + "};\n" + "void T::f() {\n" + " int i = 0;\n" + " r->p = &i;\n" + " r->pop();\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void returnLocalVariable1() { From 0566298428112b063d7072a3a3c4c56822b22a59 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:43:48 +0100 Subject: [PATCH 2/2] Update checkautovariables.cpp --- lib/checkautovariables.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index fea4d1c2533..d1e807143b2 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -648,6 +648,7 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token if (var && !var->isLocal() && !var->isArgument() && !(val.tokvalue && val.tokvalue->variable() && val.tokvalue->variable()->isStatic()) && !isVariableChanged(nextTok, tok->scope()->bodyEnd, + var->valueType() ? var->valueType()->pointer : 0, var->declarationId(), var->isGlobal(), *mSettings)) {