Fixed #4879 (false positive: uninitialized variable in inner for inside while (regression))
This commit is contained in:
parent
a381170886
commit
2265c61734
|
@ -1484,7 +1484,7 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const
|
|||
} else {
|
||||
if (isVariableUsage(tok, var.isPointer(), _tokenizer->isCPP()))
|
||||
usetok = tok;
|
||||
else if (Token::Match(tok->previous(), "[;{}] %var% =")) {
|
||||
else if (tok->strAt(1) == "=") {
|
||||
bool assign = true;
|
||||
for (const Token *tok2 = tok->next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
|
||||
if (tok2->varId() == var.varId()) {
|
||||
|
|
|
@ -2919,6 +2919,15 @@ private:
|
|||
" x += sizeof(*abc);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar2("void f(void) {\n" // #4879
|
||||
" int i;\n"
|
||||
" while (x) {\n"
|
||||
" for (i = 0; i < 5; i++)\n"
|
||||
" a[i] = b[i];\n"
|
||||
" }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void uninitvar2_4494() {
|
||||
|
|
Loading…
Reference in New Issue