Skip to content

Commit 23ad881

Browse files
committed
Fixed false positive returnLocalVariable (#7180)
1 parent 30f2bb7 commit 23ad881

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/checkautovariables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool CheckAutoVariables::isAutoVarArray(const Token *tok)
117117
return true;
118118

119119
// ValueFlow
120-
if (var->isPointer()) {
120+
if (var->isPointer() && !var->isArgument()) {
121121
for (std::list<ValueFlow::Value>::const_iterator it = tok->values.begin(); it != tok->values.end(); ++it) {
122122
const ValueFlow::Value &val = *it;
123123
if (val.tokvalue && isAutoVarArray(val.tokvalue))

test/testautovariables.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,16 @@ class TestAutoVariables : public TestFixture {
636636
" return str;\n"
637637
"}");
638638
ASSERT_EQUALS("[test.cpp:7]: (error) Pointer to local array variable returned.\n", errout.str());
639+
640+
check("char * format_reg(char *outbuffer_start) {\n"
641+
" return outbuffer_start;\n"
642+
"}\n"
643+
"void print_with_operands() {\n"
644+
" char temp[42];\n"
645+
" char *tp = temp;\n"
646+
" tp = format_reg(tp);\n"
647+
"}");
648+
ASSERT_EQUALS("", errout.str());
639649
}
640650

641651
void returnLocalVariable2() {

0 commit comments

Comments
 (0)