Fixed #9314 (false positive: (error) Uninitialized variable: ret)

This commit is contained in:
Daniel Marjamäki 2019-10-29 20:36:58 +01:00
parent cf5dd48994
commit 210232d35c
2 changed files with 16 additions and 0 deletions

View File

@ -244,6 +244,14 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<int, Var
if (!tok)
return;
if (tok->hasKnownIntValue()) {
if (tok->getKnownIntValue() == 0)
*alwaysFalse = true;
else
*alwaysTrue = true;
return;
}
if (tok->isName() || tok->str() == ".") {
while (tok && tok->str() == ".")
tok = tok->astOperand2();

View File

@ -790,6 +790,14 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("int foo() {\n"
" int i;\n"
" if (1)\n"
" i = 11;\n"
" return i;\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("int foo()\n"
"{\n"
" int i;\n"