diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 38991a89e..f6d33cc5c 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1430,6 +1430,13 @@ void CheckOther::uninitvar() // Is it an array? const bool array(tok->next()->str() == "["); + if (array) + { + // is the array initialized? + if (Token::simpleMatch(tok->next(), "[ ] =") || + Token::Match(tok->next(), "[ %any% ] =")) + continue; + } // check if variable is accessed uninitialized.. bool init = false; diff --git a/test/testother.cpp b/test/testother.cpp index 0808ac951..2fb4579c1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -944,7 +944,6 @@ private: // Check for redundant code.. Settings settings; - settings._checkCodingStyle = true; CheckOther checkOther(&tokenizer, &settings, this); checkOther.uninitvar(); } @@ -1109,6 +1108,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " char c[50] = \"\";\n" + " strcat(c, \"test\");\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" "{\n" " char s[20];\n"