Fixed #5259 (Improve check: Uninitialized variable not reported when used in array initialization)
This commit is contained in:
parent
cb119f5910
commit
35fb55d76c
|
@ -973,6 +973,16 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const Token *parent = vartok->astParent();
|
||||||
|
while (parent && parent->isCast())
|
||||||
|
parent = parent->astParent();
|
||||||
|
while (parent && parent->str() == ",")
|
||||||
|
parent = parent->astParent();
|
||||||
|
if (Token::simpleMatch(parent, "{"))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::Match(vartok->previous(), "++|--|%cop%")) {
|
if (Token::Match(vartok->previous(), "++|--|%cop%")) {
|
||||||
if (mTokenizer->isCPP() && alloc == ARRAY && Token::Match(vartok->tokAt(-4), "& %var% =|( *"))
|
if (mTokenizer->isCPP() && alloc == ARRAY && Token::Match(vartok->tokAt(-4), "& %var% =|( *"))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -3978,6 +3978,12 @@ private:
|
||||||
" if (2 < sizeof(*x)) {}\n"
|
" if (2 < sizeof(*x)) {}\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
valueFlowUninit("void foo() {\n" // #5259 - False negative
|
||||||
|
" int a;\n"
|
||||||
|
" int x[] = {a,2};\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitvar_ipa() {
|
void uninitvar_ipa() {
|
||||||
|
|
Loading…
Reference in New Issue