diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 3ad0072f4..cb6d96343 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3098,11 +3098,13 @@ std::vector getLifetimeTokens(const Token* tok, bool escape, Valu for (const ValueFlow::Value &v : vartok->values()) { if (!v.isLocalLifetimeValue()) continue; + if (v.tokvalue == tok) + continue; errorPath.insert(errorPath.end(), v.errorPath.begin(), v.errorPath.end()); - return getLifetimeTokens(v.tokvalue, escape, std::move(errorPath)); + return getLifetimeTokens(v.tokvalue, escape, std::move(errorPath), depth - 1); } } else { - return LifetimeToken::setAddressOf(getLifetimeTokens(vartok, escape, std::move(errorPath)), + return LifetimeToken::setAddressOf(getLifetimeTokens(vartok, escape, std::move(errorPath), depth - 1), !(astIsContainer(vartok) && Token::simpleMatch(vartok->astParent(), "["))); } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 0bd7f70d0..443adce5a 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -4706,6 +4706,15 @@ private: "}\n"; valueOfTok(code, "x"); + code = "void f(){\n" + " struct dwarf_data **pp;\n" + " for (pp = (struct dwarf_data **) (void *) &state->fileline_data;\n" + " *pp != NULL;\n" + " pp = &(*pp)->next)\n" + " ;\n" + "}\n"; + valueOfTok(code, "x"); + code = "void *foo(void *x);\n" "void *foo(void *x)\n" "{\n"