Uninitialized variables: Fixed false positive taking value of pointer that is allocated but not initialized

This commit is contained in:
Daniel Marjamäki 2013-12-25 14:00:27 +01:00
parent eb2ea1c28f
commit 6182394966
2 changed files with 7 additions and 1 deletions

View File

@ -1757,7 +1757,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
} }
} }
if (Token::Match(vartok->previous(), "= %var% ;|%cop%")) if (!alloc && Token::Match(vartok->previous(), "= %var% ;|%cop%"))
return true; return true;
if (Token::Match(vartok->previous(), "? %var%")) { if (Token::Match(vartok->previous(), "? %var%")) {

View File

@ -3348,6 +3348,12 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f() {\n"
" char *p = malloc(100);\n"
" x = p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// function parameter (treat it as initialized until malloc is used) // function parameter (treat it as initialized until malloc is used)
checkUninitVar2("int f(int *p) {\n" checkUninitVar2("int f(int *p) {\n"
" if (*p == 1) {}\n" // no error " if (*p == 1) {}\n" // no error