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"))
return tok;
if (Token::simpleMatch(tok->previous(), "="))
return tok;
if (pointer && Token::simpleMatch(tok->next(), "."))
return tok;
if (array && Token::simpleMatch(tok->next(), "["))
{
if (Token::simpleMatch(tok->previous(), "="))
return tok;
init = true;
return 0;
}

View File

@ -973,6 +973,13 @@ private:
"}\n");
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"
"{\n"
" int ret;\n"