Uninitialized variables: better handling of 'a[b[..]]' when b is not initialized
This commit is contained in:
parent
5766e83309
commit
61e1c4183f
|
@ -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, ";|)|="))
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue