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 = {};
|
std::vector<const Token*> toks = {};
|
||||||
if (tok->isUnaryOp("*") || parent->originalName() == "->") {
|
if (tok->isUnaryOp("*") || parent->originalName() == "->") {
|
||||||
for (const ValueFlow::Value& v : tok->values()) {
|
for (const ValueFlow::Value& v : tok->values()) {
|
||||||
if (!v.isSymbolicValue())
|
if (!v.isLocalLifetimeValue())
|
||||||
continue;
|
continue;
|
||||||
if (v.isKnown())
|
if (v.lifetimeKind != ValueFlow::Value::LifetimeKind::Address)
|
||||||
continue;
|
|
||||||
if (v.intvalue != 0)
|
|
||||||
continue;
|
continue;
|
||||||
if (!v.tokvalue)
|
if (!v.tokvalue)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -3295,6 +3295,16 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using iterator that is a temporary.\n",
|
ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:9] -> [test.cpp:10]: (error) Using iterator that is a temporary.\n",
|
||||||
errout.str());
|
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()
|
void danglingLifetimeBorrowedMembers()
|
||||||
|
|
Loading…
Reference in New Issue