Fixed #3423 (Uninitialized variable in operator>>)

This commit is contained in:
Daniel Marjamäki 2011-12-16 20:34:44 +01:00
parent 5f1fadec7b
commit 0572321572
2 changed files with 9 additions and 3 deletions

View File

@ -1165,9 +1165,6 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok) const
if (vartok->previous()->str() == "return")
return true;
if (Token::Match(vartok->next(), "++|--|%op%"))
return true;
if (Token::Match(vartok->previous(), "++|--|%op%")) {
if (vartok->previous()->str() == ">>" && _tokenizer->isCPP()) {
// assume that variable is initialized
@ -1179,6 +1176,9 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok) const
}
}
if (Token::Match(vartok->next(), "++|--|%op%"))
return true;
if (vartok->strAt(1) == "]")
return true;

View File

@ -1746,6 +1746,12 @@ private:
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: x\n", errout.str());
}
checkUninitVar2("void f() {\n"
" int i, i2;\n"
" strm >> i >> i2;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// conditional initialization
checkUninitVar2("void f() {\n"
" int x;\n"