Fix issue 9453: False positive: danglingLifetime, address of array argument (#2335)

This commit is contained in:
Paul Fultz II 2019-11-07 02:33:17 -06:00 committed by amai2012
parent 1114dc0536
commit 2e955d0f22
2 changed files with 8 additions and 1 deletions

View File

@ -3210,7 +3210,7 @@ std::vector<LifetimeToken> getLifetimeTokens(const Token* tok, ValueFlow::Value:
if (!vartok)
return {{tok, std::move(errorPath)}};
const Variable *tokvar = vartok->variable();
if (!astIsContainer(vartok) && !(tokvar && tokvar->isArray()) &&
if (!astIsContainer(vartok) && !(tokvar && tokvar->isArray() && !tokvar->isArgument()) &&
(Token::Match(vartok->astParent(), "[|*") || vartok->astParent()->originalName() == "->")) {
for (const ValueFlow::Value &v : vartok->values()) {
if (!v.isLocalLifetimeValue())

View File

@ -2205,6 +2205,13 @@ private:
" return &b.m;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #9453
check("int *ptr;\n"
"void foo(int arr[]) {\n"
" ptr = &arr[2];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeFunction() {