diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 88035c2d162..5faf6bc8e2f 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(), "=") && astIsRHS(tok)) + return true; if (astIsPointer(tok->astParent()) && !Token::simpleMatch(tok->astParent(), "return")) return true; if (tok->astParent()->isConstOp()) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 4f616f6043c..0b8a28bacc7 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -743,6 +743,17 @@ class TestValueFlow : public TestFixture { lifetimes = lifetimeValues(code, "return"); // don't crash ASSERT_EQUALS(true, lifetimes.empty()); } + + { + const char code[] = "void f() {\n" // #13076 + " 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() {