From c3dff9a6d3753635703c26e30278b79e62e2e4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 3 Nov 2009 21:02:16 +0100 Subject: [PATCH] Fixed #893 (False Positive: Uninitialized variable b in a[0] = b[0] = '\0';) --- lib/checkother.cpp | 10 ++++++++++ test/testother.cpp | 7 +++++++ 2 files changed, 17 insertions(+) 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"