From 9f62740e1d233944090050bcd871a0d2660a5a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 12 Dec 2013 08:44:00 +0100 Subject: [PATCH] Fixed #5236 (varid 0: vlc: src/misc/objects.c:126) --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index bfcc2ee5b..8d8381918 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -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()) && diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 4378cdb8b..cb43ab3dc 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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()); }