Fixed #5236 (varid 0: vlc: src/misc/objects.c:126)

This commit is contained in:
Daniel Marjamäki 2013-12-12 08:44:00 +01:00
parent a4f9cb78d5
commit 9f62740e1d
2 changed files with 7 additions and 1 deletions

View File

@ -1099,7 +1099,7 @@ void CheckUninitVar::checkScope(const Scope* scope)
if (scope->function) {
for (unsigned int i = 0; i < scope->function->argCount(); i++) {
const Variable *arg = scope->function->getArgumentVar(i);
if (arg && Token::Match(arg->typeStartToken(), "struct| %type% * %var% [,)]")) {
if (arg && arg->declarationId() && Token::Match(arg->typeStartToken(), "struct| %type% * %var% [,)]")) {
// Treat the pointer as initialized until it is assigned by malloc
for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "[;{}] %varid% = %var% (", arg->declarationId()) &&

View File

@ -3285,6 +3285,12 @@ private:
" struct AB *ab = malloc(sizeof(struct AB));\n"
" do_something(ab);\n"
"}");
ASSERT_EQUALS("", errout.str());
// analysis failed. varid 0.
checkUninitVar2("void *vlc_custom_create (vlc_object_t *parent, size_t length, const char *typename) {\n"
" assert (length >= sizeof (vlc_object_t));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}