From 825018ca8275c1067311f34b930a9276a9fefbb3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:39:03 +0100 Subject: [PATCH 1/5] Update valueflow.cpp --- lib/valueflow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 88035c2d162..786c2f5b704 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2785,6 +2785,8 @@ static bool isDecayedPointer(const Token *tok) return false; if (!tok->astParent()) return false; + if (Token::simpleMatch(tok->astParent(), "=")) + return true; if (astIsPointer(tok->astParent()) && !Token::simpleMatch(tok->astParent(), "return")) return true; if (tok->astParent()->isConstOp()) From 79b69c3e167e97077118d79b648a9994886058dd Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:41:56 +0100 Subject: [PATCH 2/5] Update testvalueflow.cpp --- test/testvalueflow.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 4f616f6043c..8fd22f30065 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -743,6 +743,18 @@ class TestValueFlow : public TestFixture { lifetimes = lifetimeValues(code, "return"); // don't crash ASSERT_EQUALS(true, lifetimes.empty()); } + + { + const char code[] = "void g(struct S*);\n" // #13076 + "void f() {\n" + " char a[10];\n" + " struct S s = { sizeof(a), 0 };\n" + " s.p = a;\n" + "}\n"; + lifetimes = lifetimeValues(code, "= a"); + ASSERT_EQUALS(true, lifetimes.size() == 1); + ASSERT_EQUALS(true, lifetimes.front() == "a"); + } } void valueFlowArrayElement() { From 03c3ce1330fc5c3210d8dfa5173c087192989266 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:44:09 +0100 Subject: [PATCH 3/5] Update valueflow.cpp --- lib/valueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 786c2f5b704..5faf6bc8e2f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2785,7 +2785,7 @@ static bool isDecayedPointer(const Token *tok) return false; if (!tok->astParent()) return false; - if (Token::simpleMatch(tok->astParent(), "=")) + if (Token::simpleMatch(tok->astParent(), "=") && astIsRHS(tok)) return true; if (astIsPointer(tok->astParent()) && !Token::simpleMatch(tok->astParent(), "return")) return true; From 54549ea7c8a47d8e5607afabcd9a09d8ec8bf86a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 2 Jan 2025 13:01:39 +0100 Subject: [PATCH 4/5] Update testvalueflow.cpp --- test/testvalueflow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 8fd22f30065..e085da651d3 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -743,9 +743,9 @@ class TestValueFlow : public TestFixture { lifetimes = lifetimeValues(code, "return"); // don't crash ASSERT_EQUALS(true, lifetimes.empty()); } - + { - const char code[] = "void g(struct S*);\n" // #13076 + const char code[] = "void g(struct S*);\n" // #13076 "void f() {\n" " char a[10];\n" " struct S s = { sizeof(a), 0 };\n" From e1aeb45ffd1c46cf6f7944e10e0c77dff6f29020 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 2 Jan 2025 13:06:59 +0100 Subject: [PATCH 5/5] Update testvalueflow.cpp --- test/testvalueflow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index e085da651d3..0b8a28bacc7 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -745,8 +745,7 @@ class TestValueFlow : public TestFixture { } { - const char code[] = "void g(struct S*);\n" // #13076 - "void f() {\n" + const char code[] = "void f() {\n" // #13076 " char a[10];\n" " struct S s = { sizeof(a), 0 };\n" " s.p = a;\n"