Fixed #5245 (false positive: Uninitialized variable (assignment inside ternary operator))

This commit is contained in:
Daniel Marjamäki 2014-01-25 10:12:50 +01:00
parent 35b51468cb
commit bc9ad08831
2 changed files with 7 additions and 1 deletions

View File

@ -1775,7 +1775,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all
tok2 = tok2->link(); tok2 = tok2->link();
else if (tok2->str() == ":") else if (tok2->str() == ":")
rhs = true; rhs = true;
else if (Token::Match(tok2, "[)];,{}]")) else if (Token::Match(tok2, "[)];,{}=]"))
break; break;
else if (rhs && tok2->varId() == vartok->varId()) else if (rhs && tok2->varId() == vartok->varId())
return true; return true;

View File

@ -2191,6 +2191,12 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar2("int f(int a) {\n"
" int result;\n"
" foo() ? result = 1 : result = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
// = { .. } // = { .. }
checkUninitVar2("int f() {\n" checkUninitVar2("int f() {\n"
" int a;\n" " int a;\n"