Fixed #4879 (false positive: uninitialized variable in inner for inside while (regression))

This commit is contained in:
Daniel Marjamäki 2013-06-26 17:02:57 +02:00
parent a381170886
commit 2265c61734
2 changed files with 10 additions and 1 deletions

View File

@ -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()) {

View File

@ -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() {