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:
Paul Fultz II 2019-06-24 11:52:17 -05:00 committed by Daniel Marjamäki
parent f36d671bc5
commit 66e0f06494
2 changed files with 8 additions and 0 deletions

View File

@ -3366,6 +3366,8 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
}
// container lifetimes
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;
const Library::Container * container = settings->library.detectContainer(tok->variable()->typeStartToken());
if (!container)

View File

@ -1730,6 +1730,12 @@ private:
" }\n"
"};\n");
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() {