Fix 10467: FP mismatchingContainers with array of vectors (#3453)

This commit is contained in:
Paul Fultz II 2021-09-09 13:43:46 -05:00 committed by GitHub
parent b0b3f7ec2d
commit 9ece849d80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -3621,11 +3621,17 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList *tokenlist, ErrorLog
if (i->container != returnContainer) if (i->container != returnContainer)
continue; continue;
const Token * const argTok = args[argnr - 1]; const Token * const argTok = args[argnr - 1];
bool forward = false;
for (ValueFlow::Value val : argTok->values()) {
if (!val.isLifetimeValue())
continue;
val.errorPath.emplace_back(argTok, "Passed to '" + tok->str() + "'.");
setTokenValue(tok->next(), val, settings);
forward = true;
}
// Check if lifetime is available to avoid adding the lifetime twice // Check if lifetime is available to avoid adding the lifetime twice
ValueFlow::Value val = getLifetimeObjValue(argTok); if (forward) {
if (val.tokvalue) { valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings);
LifetimeStore{argTok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::LifetimeKind::Iterator}.byVal(
tok->next(), tokenlist, errorLogger, settings);
break; break;
} }
} }

View File

@ -1704,6 +1704,16 @@ private:
" if (c.end() == d.end()) {}\n" " if (c.end() == d.end()) {}\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #10467
check("void f(std::array<std::vector<int>, N>& A) {\n"
" for (auto& a : A) {\n"
" auto it = std::find_if(a.begin(), a.end(), \n"
" [](auto i) { return i == 0; });\n"
" if (it != a.end()) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
// Dereferencing invalid pointer // Dereferencing invalid pointer