Uninitialized variables: Improved handling of function calls
This commit is contained in:
parent
415ee977d8
commit
cf84c211ed
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue