Fix 10683: FP danglingTemporaryLifetime with pointer to vector (#3685)

This commit is contained in:
Paul Fultz II 2022-01-10 00:34:26 -06:00 committed by GitHub
parent fe7595cd9d
commit 4ef20f8f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -4200,11 +4200,9 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
std::vector<const Token*> toks = {};
if (tok->isUnaryOp("*") || parent->originalName() == "->") {
for (const ValueFlow::Value& v : tok->values()) {
if (!v.isSymbolicValue())
if (!v.isLocalLifetimeValue())
continue;
if (v.isKnown())
continue;
if (v.intvalue != 0)
if (v.lifetimeKind != ValueFlow::Value::LifetimeKind::Address)
continue;
if (!v.tokvalue)
continue;

View File

@ -3295,6 +3295,16 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using iterator that is a temporary.\n",
errout.str());
check("void f(bool b) {\n"
" std::vector<int> ints = g();\n"
" auto *ptr = &ints;\n"
" if (b)\n"
" ptr = &ints;\n"
" for (auto it = ptr->begin(); it != ptr->end(); ++it)\n"
" {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeBorrowedMembers()