From 23ad881c643d1e142331d94d01e45269062ff835 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 30 Jan 2016 20:02:39 +0100 Subject: [PATCH] Fixed false positive returnLocalVariable (#7180) --- lib/checkautovariables.cpp | 2 +- test/testautovariables.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 7f3f22a3c..dd339a8c7 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -117,7 +117,7 @@ bool CheckAutoVariables::isAutoVarArray(const Token *tok) return true; // ValueFlow - if (var->isPointer()) { + if (var->isPointer() && !var->isArgument()) { for (std::list::const_iterator it = tok->values.begin(); it != tok->values.end(); ++it) { const ValueFlow::Value &val = *it; if (val.tokvalue && isAutoVarArray(val.tokvalue)) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 9086a192e..74ff2486b 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -636,6 +636,16 @@ private: " return str;\n" "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Pointer to local array variable returned.\n", errout.str()); + + check("char * format_reg(char *outbuffer_start) {\n" + " return outbuffer_start;\n" + "}\n" + "void print_with_operands() {\n" + " char temp[42];\n" + " char *tp = temp;\n" + " tp = format_reg(tp);\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void returnLocalVariable2() {