Fixed #764 (usage of unitialized variable not detected)

This commit is contained in:
Daniel Marjamäki 2009-11-02 19:58:49 +01:00
parent 169bcfcff2
commit 8d57cef7f9
2 changed files with 10 additions and 2 deletions

View File

@ -1331,13 +1331,14 @@ static const Token *uninitvar_checkscope(const Token *tok, const unsigned int va
if (Token::simpleMatch(tok->previous(), "return")) if (Token::simpleMatch(tok->previous(), "return"))
return tok; return tok;
if (Token::simpleMatch(tok->previous(), "="))
return tok;
if (pointer && Token::simpleMatch(tok->next(), ".")) if (pointer && Token::simpleMatch(tok->next(), "."))
return tok; return tok;
if (array && Token::simpleMatch(tok->next(), "[")) if (array && Token::simpleMatch(tok->next(), "["))
{ {
if (Token::simpleMatch(tok->previous(), "="))
return tok;
init = true; init = true;
return 0; return 0;
} }

View File

@ -973,6 +973,13 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkUninitVar("void a()\n"
"{\n"
" int x;\n"
" int y = x;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n", errout.str());
checkUninitVar("int a()\n" checkUninitVar("int a()\n"
"{\n" "{\n"
" int ret;\n" " int ret;\n"