Fix issue 9219: False positive, returnDanglingLifetime (#2026)
* Check for pointer deref for container methods * Formatting
This commit is contained in:
parent
5ad5cfcc29
commit
60b670babd
|
@ -3371,7 +3371,9 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
|
||||||
valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings);
|
valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings);
|
||||||
}
|
}
|
||||||
// container lifetimes
|
// container lifetimes
|
||||||
else if (tok->variable() && Token::Match(tok, "%var% . begin|cbegin|rbegin|crbegin|end|cend|rend|crend|data|c_str|find|insert (")) {
|
else if (tok->variable() &&
|
||||||
|
Token::Match(tok, "%var% . begin|cbegin|rbegin|crbegin|end|cend|rend|crend|data|c_str|find|insert (") &&
|
||||||
|
tok->next()->originalName() != "->") {
|
||||||
if (Token::simpleMatch(tok->tokAt(2), "find") && !astIsIterator(tok->tokAt(3)))
|
if (Token::simpleMatch(tok->tokAt(2), "find") && !astIsIterator(tok->tokAt(3)))
|
||||||
continue;
|
continue;
|
||||||
ErrorPath errorPath;
|
ErrorPath errorPath;
|
||||||
|
|
|
@ -1757,6 +1757,13 @@ private:
|
||||||
" return y.find(x);\n"
|
" return y.find(x);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("std::string* f();\n"
|
||||||
|
"const char* g() {\n"
|
||||||
|
" std::string* var = f();\n"
|
||||||
|
" return var->c_str();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void danglingLifetime() {
|
void danglingLifetime() {
|
||||||
|
|
Loading…
Reference in New Issue