From 4b04ed9ad9a5d0746c649dd05667d11cabe20382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 8 Nov 2009 07:31:01 +0100 Subject: [PATCH] Fixed #910 (false positive: uninitialized variable for array) --- lib/checkother.cpp | 3 +++ test/testother.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d7ed416b0..468945f2f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1361,6 +1361,9 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token if (tok->varId() == varid) { + if (array && !Token::simpleMatch(tok->next(), "[")) + continue; + if (Token::simpleMatch(tok->previous(), "return")) return tok; diff --git a/test/testother.cpp b/test/testother.cpp index a2e0e7a34..5924eacac 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1108,6 +1108,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " char a[10], *p;\n" + " *(p = a) = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" "{\n" " char c[50] = \"\";\n"