From 4668359b51931d51d8fe9bcc17ba34b1000623a3 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Tue, 29 Jun 2010 08:38:24 +0200 Subject: [PATCH] Fixed #1808 (false positive: uninitialized variable with multiple assignment) --- lib/checkother.cpp | 7 ++++++- test/testunusedvar.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a0e094737..908fa9699 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1301,8 +1301,13 @@ void CheckOther::functionVariableUsage() variables.write(varid1); } + const Token *equal = tok->next(); + + if (Token::Match(tok->next(), "[ %any% ]")) + equal = tok->tokAt(4); + // checked for chained assignments - if (tok != start && tok->next()->str() == "=") + if (tok != start && equal->str() == "=") { Variables::VariableUsage *var = variables.find(tok->varId()); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 0e12833bf..51bfd9b9a 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -68,6 +68,7 @@ private: TEST_CASE(localvar20); // ticket #1799 TEST_CASE(localvar21); // ticket #1807 TEST_CASE(localvar22); // ticket #1811 + TEST_CASE(localvar23); // ticket #1808 TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias3); // ticket #1639 @@ -1203,6 +1204,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void localvar23() // ticket #1808 + { + functionVariableUsage("int foo(int c)\n" + "{\n" + " int a;\n" + " int b[10];\n" + " a = b[c] = 0;\n" + " return a;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void localvaralias1() { functionVariableUsage("void foo()\n"