Fix 10683: FP danglingTemporaryLifetime with pointer to vector (#3685)
This commit is contained in:
parent
fe7595cd9d
commit
4ef20f8f1e
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue