Fixed #5245 (false positive: Uninitialized variable (assignment inside ternary operator))
This commit is contained in:
parent
35b51468cb
commit
bc9ad08831
|
@ -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;
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in New Issue