Uninitialized variables: better handling of 'a[b[..]]' when b is not initialized

This commit is contained in:
Daniel Marjamäki 2010-04-05 09:04:30 +02:00
parent 5766e83309
commit 61e1c4183f
2 changed files with 9 additions and 2 deletions

View File

@ -1992,9 +1992,9 @@ private:
return &tok;
}
if (Token::Match(tok.previous(), "[;{}] %var% ="))
if (Token::Match(tok.previous(), "[;{}] %var% =|["))
{
// using same variable rhs?
// check variable usages in rhs/index
for (const Token *tok2 = tok.tokAt(2); tok2; tok2 = tok2->next())
{
if (Token::Match(tok2, ";|)|="))

View File

@ -1603,6 +1603,13 @@ private:
// arrays..
void uninitvar_arrays()
{
checkUninitVar("int f()\n"
"{\n"
" char a[10];\n"
" a[a[0]] = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: a\n", errout.str());
checkUninitVar("int f()\n"
"{\n"
" char a[10];\n"