Fixed #5658 (false positive: (error) Uninitialized variable: s)

This commit is contained in:
Daniel Marjamäki 2014-04-10 15:59:37 +02:00
parent baf8d09a0d
commit c8ae1e4751
2 changed files with 13 additions and 1 deletions

View File

@ -1607,7 +1607,10 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const
assign = false; assign = false;
break; break;
} else if (tok2->str() == "(") { } else if (tok2->str() == "(") {
++indentlevel; if (Token::Match(tok2->astOperand1(), "sizeof"))
tok2 = tok2->link();
else
++indentlevel;
} else if (tok2->str() == ")") { } else if (tok2->str() == ")") {
if (indentlevel <= 1U) if (indentlevel <= 1U)
break; break;

View File

@ -3265,6 +3265,15 @@ private:
" }\n" " }\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f(void) {\n" // #5658
" struct Foo *foo;\n"
" while (true) {\n"
" foo = malloc(sizeof(*foo));\n"
" foo->x = 0;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void uninitvar2_4494() { void uninitvar2_4494() {