Fixed #2946 (False positive: Uninitialized buffer variable (init in subfunction))

This commit is contained in:
Daniel Marjamäki 2011-07-27 10:34:12 +02:00
parent 4e55fb604c
commit 5cb701d3c1
2 changed files with 19 additions and 2 deletions

View File

@ -1073,6 +1073,8 @@ public:
continue;
}
/// @todo enable this code. if pointer is written in function then dead pointer is invalid but valid pointer is ok.
/*
if (Token::Match(tok2, "const| struct| %type% * %var% ,|)"))
{
while (tok2->isName())
@ -1080,6 +1082,7 @@ public:
tok2 = tok2->tokAt(2);
continue;
}
*/
break;
}

View File

@ -1326,7 +1326,9 @@ private:
ASSERT_EQUALS("rename", analyseFunctions("int rename (const char oldname[], const char newname[]);"));
ASSERT_EQUALS("", analyseFunctions("void foo(int &x) { x = 0; }"));
ASSERT_EQUALS("", analyseFunctions("void foo(s x) { }"));
ASSERT_EQUALS("foo", analyseFunctions("void foo(Fred *fred) { fred->x = 0; }"));
// TODO: it's ok to pass a valid pointer to "foo". See #2775 and #2946
TODO_ASSERT_EQUALS("foo", "", analyseFunctions("void foo(Fred *fred) { fred->x = 0; }"));
ASSERT_EQUALS("", analyseFunctions("void foo(int *x) { x[0] = 0; }"));
// function calls..
checkUninitVar("void assignOne(int &x)\n"
@ -1489,7 +1491,19 @@ private:
" struct Fred *p;\n"
" a(p);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: p\n", errout.str());
// TODO: See #2946
TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: p\n", "", errout.str());
// #2946 - FP array is initialized in subfunction
checkUninitVar("void a(char *buf) {\n"
" buf[0] = 0;\n"
"}\n"
"void b() {\n"
" char buf[10];\n"
" a(buf);\n"
" buf[1] = buf[0];\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// valid and invalid use of 'int a(int x) { return x + x; }'