Fixx issue 9163: FP returnDanglingLifetime - returning std::string::find (#1912)
* Fixx issue 9163: FP returnDanglingLifetime - returning std::string::find * Use simpleMatch
This commit is contained in:
parent
f36d671bc5
commit
66e0f06494
|
@ -3366,6 +3366,8 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
|
||||||
}
|
}
|
||||||
// container lifetimes
|
// container lifetimes
|
||||||
else if (tok->variable() && Token::Match(tok, "%var% . begin|cbegin|rbegin|crbegin|end|cend|rend|crend|data|c_str|find (")) {
|
else if (tok->variable() && Token::Match(tok, "%var% . begin|cbegin|rbegin|crbegin|end|cend|rend|crend|data|c_str|find (")) {
|
||||||
|
if (Token::simpleMatch(tok->tokAt(2), "find") && !astIsIterator(tok->tokAt(3)))
|
||||||
|
continue;
|
||||||
ErrorPath errorPath;
|
ErrorPath errorPath;
|
||||||
const Library::Container * container = settings->library.detectContainer(tok->variable()->typeStartToken());
|
const Library::Container * container = settings->library.detectContainer(tok->variable()->typeStartToken());
|
||||||
if (!container)
|
if (!container)
|
||||||
|
|
|
@ -1730,6 +1730,12 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("size_t f(const std::string& x) {\n"
|
||||||
|
" std::string y = \"x\";\n"
|
||||||
|
" return y.find(x);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void danglingLifetime() {
|
void danglingLifetime() {
|
||||||
|
|
Loading…
Reference in New Issue