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") if (vartok->previous()->str() == "return")
return true; return true;
if (Token::Match(vartok->next(), "++|--|%op%"))
return true;
if (Token::Match(vartok->previous(), "++|--|%op%")) { if (Token::Match(vartok->previous(), "++|--|%op%")) {
if (vartok->previous()->str() == ">>" && _tokenizer->isCPP()) { if (vartok->previous()->str() == ">>" && _tokenizer->isCPP()) {
// assume that variable is initialized // 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) == "]") if (vartok->strAt(1) == "]")
return true; return true;

View File

@ -1746,6 +1746,12 @@ private:
ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: x\n", errout.str()); 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 // conditional initialization
checkUninitVar2("void f() {\n" checkUninitVar2("void f() {\n"
" int x;\n" " int x;\n"