Fix issue 9453: False positive: danglingLifetime, address of array argument (#2335)
This commit is contained in:
parent
1114dc0536
commit
2e955d0f22
|
@ -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())
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue