Fixed #6869 (False positive: uninitvar, array passed to function)

This commit is contained in:
Daniel Marjamäki 2015-08-05 10:19:17 +02:00
parent e598b07a6d
commit 4bebb80300
2 changed files with 10 additions and 3 deletions

View File

@ -896,15 +896,14 @@ int CheckUninitVar::isFunctionParUsage(const Token *vartok, bool pointer, Alloc
// is this a function call?
if (start && Token::Match(start->previous(), "%name% (")) {
const bool address(vartok->previous()->str() == "&");
const bool array(vartok->variable() && vartok->variable()->isArray());
// check how function handle uninitialized data arguments..
const Function *func = start->previous()->function();
if (func) {
const Variable *arg = func->getArgumentVar(argumentNumber);
if (arg) {
const Token *argStart = arg->typeStartToken();
if (!address && Token::Match(argStart, "struct| %type% [,)]"))
return 1;
if (!address && Token::Match(argStart, "struct| %type% %name% [,)]"))
if (!address && !array && Token::Match(argStart, "struct| %type% %name%| [,)]"))
return 1;
if (pointer && !address && alloc == NO_ALLOC && Token::Match(argStart, "struct| %type% * %name% [,)]"))
return 1;

View File

@ -1336,6 +1336,14 @@ private:
" int **b = a[0];\n"
"}");
ASSERT_EQUALS("", errout.str());
// #6869 - FP when passing uninit array to function
checkUninitVar("void bar(PSTR x);\n"
"void foo() {\n"
" char x[10];\n"
" bar(x);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// alloc..