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"))
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in New Issue