Fixed #764 (usage of unitialized variable not detected)
This commit is contained in:
parent
169bcfcff2
commit
8d57cef7f9
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue