fix false positive introduced by previous false negative fix commit

This commit is contained in:
Robert Reif 2011-09-02 10:39:04 -04:00
parent 833865e736
commit e19cbf0cdd
2 changed files with 8 additions and 1 deletions

View File

@ -168,7 +168,7 @@ void CheckAutoVariables::autoVariables()
else if (Token::Match(tok, "return & %var% ;") && tok->tokAt(2)->varId()) else if (Token::Match(tok, "return & %var% ;") && tok->tokAt(2)->varId())
{ {
const Variable * var1 = symbolDatabase->getVariableFromVarId(tok->tokAt(2)->varId()); const Variable * var1 = symbolDatabase->getVariableFromVarId(tok->tokAt(2)->varId());
if (var1 && var1->isArgument()) if (var1 && var1->isArgument() && var1->typeEndToken()->str() != "&")
errorReturnAddressOfFunctionParameter(tok, tok->strAt(2)); errorReturnAddressOfFunctionParameter(tok, tok->strAt(2));
} }
// Invalid pointer deallocation // Invalid pointer deallocation

View File

@ -593,6 +593,13 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Return the address of function parameter 'y'\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Return the address of function parameter 'y'\n", errout.str());
check("const int * foo(const int & y)\n"
"{\n"
" return &y;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
}; };