Fixed #8058 (False positive returnAddressOfAutoVariable within lambda)

This commit is contained in:
Daniel Marjamäki 2018-11-11 07:52:38 +01:00
parent 93cde415a7
commit ee2dfb6604
2 changed files with 15 additions and 0 deletions

View File

@ -230,6 +230,11 @@ void CheckAutoVariables::autoVariables()
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Scope * scope : symbolDatabase->functionScopes) { for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) { for (const Token *tok = scope->bodyStart; tok && tok != scope->bodyEnd; tok = tok->next()) {
// Skip lambda..
if (const Token *lambdaEndToken = findLambdaEndToken(tok)) {
tok = lambdaEndToken;
continue;
}
// Critical assignment // Critical assignment
if (Token::Match(tok, "[;{}] %var% = & %var%") && isRefPtrArg(tok->next()) && isAutoVar(tok->tokAt(4))) { if (Token::Match(tok, "[;{}] %var% = & %var%") && isRefPtrArg(tok->next()) && isAutoVar(tok->tokAt(4))) {
if (checkRvalueExpression(tok->tokAt(4))) if (checkRvalueExpression(tok->tokAt(4)))

View File

@ -82,6 +82,7 @@ private:
TEST_CASE(testautovar_return1); TEST_CASE(testautovar_return1);
TEST_CASE(testautovar_return2); TEST_CASE(testautovar_return2);
TEST_CASE(testautovar_return3); TEST_CASE(testautovar_return3);
TEST_CASE(testautovar_return4);
TEST_CASE(testautovar_extern); TEST_CASE(testautovar_extern);
TEST_CASE(testinvaliddealloc); TEST_CASE(testinvaliddealloc);
TEST_CASE(testinvaliddealloc_C); TEST_CASE(testinvaliddealloc_C);
@ -497,6 +498,15 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void testautovar_return4() {
// #8058 - FP ignore return in lambda
check("void foo() {\n"
" int cond2;\n"
" dostuff([&cond2]() { return &cond2; });\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void testautovar_extern() { void testautovar_extern() {
check("struct foo *f()\n" check("struct foo *f()\n"
"{\n" "{\n"