From e19cbf0cdd157cfd0d0cd0273a2f5f71bcedc57c Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 2 Sep 2011 10:39:04 -0400 Subject: [PATCH] fix false positive introduced by previous false negative fix commit --- lib/checkautovariables.cpp | 2 +- test/testautovariables.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index a72f2a88e..9a71264cc 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -168,7 +168,7 @@ void CheckAutoVariables::autoVariables() else if (Token::Match(tok, "return & %var% ;") && 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)); } // Invalid pointer deallocation diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 18a8ebb56..dbe19d818 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -593,6 +593,13 @@ private: "}\n"); 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()); } };