Fix issue 9883: endless recursion in getLifetimeTokens (#2786)

This commit is contained in:
Daniel Marjamäki 2020-09-08 20:14:54 +02:00 committed by GitHub
commit 18e99176e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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"