From ad0908cb3fe38c0427c0d769490d378a5edae803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 25 Jun 2010 19:39:30 +0200 Subject: [PATCH] Fixed #1808 (false positive: uninitialized variable with multiple assignment) --- lib/checkother.cpp | 9 +++++++++ test/testother.cpp | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 11fbe69be..a0e094737 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2948,6 +2948,15 @@ private: !Token::Match(tok2->previous(), "&|::") && !Token::simpleMatch(tok2->next(), "=")) { + // Multiple assignments.. + if (Token::simpleMatch(tok2->next(), "[")) + { + const Token * tok3 = tok2; + while (Token::simpleMatch(tok3->next(), "[")) + tok3 = tok3->next()->link(); + if (Token::simpleMatch(tok3, "] =")) + continue; + } bool foundError; if (tok2->previous()->str() == "*" || tok2->next()->str() == "[") foundError = use_array_or_pointer_data(checks, tok2); diff --git a/test/testother.cpp b/test/testother.cpp index 23ed8dae6..e2e1a56c1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1817,6 +1817,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " char a, b[10];\n" + " a = b[0] = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" "{\n" " char a[10], b[10];\n"