diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b155f77cd..9ae03afcb 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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, ";|)|=")) diff --git a/test/testother.cpp b/test/testother.cpp index cf1d85f34..b52bd9295 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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"