Uninitialized variables: Fixed false positive taking value of pointer that is allocated but not initialized
This commit is contained in:
parent
eb2ea1c28f
commit
6182394966
|
@ -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%")) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue