Uninitialized variables: Fixed false positive for 'p=malloc; if (python tools/daca2.py b)'
This commit is contained in:
parent
9f62740e1d
commit
4e7594748d
|
@ -1740,7 +1740,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]")) {
|
if (vartok->previous()->str() != "&" || !Token::Match(vartok->tokAt(-2), "[(,=?:]")) {
|
||||||
return true;
|
return (pointer && alloc && vartok->strAt(-1) != "*") ? false : true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3263,6 +3263,15 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized struct member: ab.a\n", errout.str());
|
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)
|
// 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
|
||||||
|
@ -3287,7 +3296,7 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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"
|
checkUninitVar2("void *vlc_custom_create (vlc_object_t *parent, size_t length, const char *typename) {\n"
|
||||||
" assert (length >= sizeof (vlc_object_t));\n"
|
" assert (length >= sizeof (vlc_object_t));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
Loading…
Reference in New Issue