Fix issue 9883: endless recursion in getLifetimeTokens

This commit is contained in:
Paul 2020-09-08 11:33:29 -05:00
parent e802d85315
commit d5489fd1f0
2 changed files with 13 additions and 2 deletions

View File

@ -3098,11 +3098,13 @@ std::vector<LifetimeToken> 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(), "[")));
}
}

View File

@ -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"