Uninitialized variables : fixed false positives when passing address of pointer to function.

This commit is contained in:
Daniel Marjamäki 2012-12-21 16:57:49 +01:00
parent 3bd08552ab
commit 415ee977d8
2 changed files with 9 additions and 2 deletions

View File

@ -1311,7 +1311,7 @@ bool CheckUninitVar::isVariableUsage(const Scope* scope, const Token *vartok, bo
argStart = argStart->previous();
if (argStart->isStandardType() && Token::Match(argStart, "%type% %var% [,)]"))
return true;
if (Token::Match(argStart, "const"))
if (!(pointer && address) && Token::Match(argStart, "const"))
return true;
}
}

View File

@ -2375,7 +2375,7 @@ private:
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: a\n", errout.str());
}
// Handling of unknown types. Assume they are POD in C.
// Handling of function calls
void uninitvar2_func() {
checkUninitVar2("void a(char c);\n"
"void b() {\n"
@ -2411,6 +2411,13 @@ private:
" a(&abc);\n"
"}", "test.c");
ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: abc\n", errout.str());
checkUninitVar2("void a(const char **p);\n"
"void b() {\n"
" const char *s;\n"
" a(&s);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};