Fixed false positive returnLocalVariable (#7180)

This commit is contained in:
PKEuS 2016-01-30 20:02:39 +01:00
parent 30f2bb7796
commit 23ad881c64
2 changed files with 11 additions and 1 deletions

View File

@ -117,7 +117,7 @@ bool CheckAutoVariables::isAutoVarArray(const Token *tok)
return true;
// ValueFlow
if (var->isPointer()) {
if (var->isPointer() && !var->isArgument()) {
for (std::list<ValueFlow::Value>::const_iterator it = tok->values.begin(); it != tok->values.end(); ++it) {
const ValueFlow::Value &val = *it;
if (val.tokvalue && isAutoVarArray(val.tokvalue))

View File

@ -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() {