Uninitialized variables: Fixed false positive for 'p=malloc; if (python tools/daca2.py b)'

This commit is contained in:
Daniel Marjamäki 2013-12-12 09:17:41 +01:00
parent 9f62740e1d
commit 4e7594748d
2 changed files with 11 additions and 2 deletions

View File

@ -1740,7 +1740,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
}
if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]")) {
return true;
return (pointer && alloc && vartok->strAt(-1) != "*") ? false : true;
}
}

View File

@ -3263,6 +3263,15 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab.a\n", errout.str());
checkUninitVar2("struct t_udf_file { int dir_left; };\n"
"\n"
"void f() {\n"
" struct t_udf_file *newf;\n"
" newf = malloc(sizeof(*newf));\n"
" if (!newf) return 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// function parameter (treat it as initialized until malloc is used)
checkUninitVar2("int f(int *p) {\n"
" if (*p == 1) {}\n" // no error
@ -3287,7 +3296,7 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
// analysis failed. varid 0.
// 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");