From 1769240e1531df036e2639800857cd34dd82ef1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 28 Dec 2012 18:18:36 +0100 Subject: [PATCH] Fixed #4022 (false positive: (style) Variable 'sort_entry' is assigned a value that is never used) --- lib/checkunusedvar.cpp | 4 ++-- test/testunusedvar.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 6a25df691..f4b1da635 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -547,13 +547,13 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de else variables.read(varid2, tok); } else { - variables.read(varid2, tok); + variables.readAll(varid2, tok); } } } else if (var1->_type == Variables::reference) { variables.alias(varid1, varid2, true); } else { - if (var2->_type == Variables::pointer && tok->strAt(1) == "[") + if ((var2->_type == Variables::pointer || var2->_type == Variables::pointerArray) && tok->strAt(1) == "[") variables.readAliases(varid2, tok); variables.read(varid2, tok); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 975820940..019d805a1 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2156,6 +2156,24 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'a' is not assigned a value.\n", errout.str()); + functionVariableUsage("void foo() {\n" // #4022 - FP (a is assigned a value that is never used) + " int a[2], *b[2];\n" + " a[0] = 123;\n" + " b[0] = &a[0];\n" + " int *d = b[0];\n" + " return *d;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("void foo() {\n" // #4022 - FP (a is assigned a value that is never used) + " entry a[2], *b[2];\n" + " a[0].value = 123;\n" + " b[0] = &a[0];\n" + " int d = b[0].value;\n" + " return d;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + functionVariableUsage("struct S { char c[100]; };\n" "void foo()\n" "{\n"