diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 47af286cb..a0a13860b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1294,6 +1294,16 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token init = true; return 0; } + + if (Token::simpleMatch(tok->next(), "[")) + { + const Token *tok2 = Token::findmatch(tok, "]"); + if (Token::simpleMatch(tok2 ? tok2->next() : 0, "=")) + { + init = true; + return 0; + } + } } if (Token::Match(tok, "%var% (")) diff --git a/test/testother.cpp b/test/testother.cpp index 9b99c025d..f2613f025 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1078,6 +1078,13 @@ private: ASSERT_EQUALS("", errout.str()); // arrays.. + checkUninitVar("void f()\n" + "{\n" + " char a[10], b[10];\n" + " a[0] = b[0] = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" "{\n" " char s[20];\n"