Uninitialized variables: Improved handling of function calls

This commit is contained in:
Daniel Marjamäki 2012-12-21 17:04:15 +01:00
parent 415ee977d8
commit cf84c211ed
2 changed files with 13 additions and 2 deletions

View File

@ -1309,9 +1309,13 @@ bool CheckUninitVar::isVariableUsage(const Scope* scope, const Token *vartok, bo
const Token *argStart = arg->typeStartToken();
while (argStart->previous() && argStart->previous()->isName())
argStart = argStart->previous();
if (argStart->isStandardType() && Token::Match(argStart, "%type% %var% [,)]"))
if (Token::Match(argStart, "const| %type% %var% [,)]"))
return true;
if (!(pointer && address) && Token::Match(argStart, "const"))
if (Token::Match(argStart, "const %type% & %var% [,)]"))
return true;
if (pointer && Token::Match(argStart, "%type% * %var% [,)]"))
return true;
if (!(pointer && address) && Token::Match(argStart, "const %type% * %var% [,)]"))
return true;
}
}

View File

@ -2412,6 +2412,13 @@ private:
"}", "test.c");
ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: abc\n", errout.str());
checkUninitVar2("void a(char *p);\n"
"void b() {\n"
" char *s;\n"
" a(s);\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
checkUninitVar2("void a(const char **p);\n"
"void b() {\n"
" const char *s;\n"