From 680d3f13120857f1c81661b8f539da88d0bf3bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 11 Jan 2014 20:53:23 +0100 Subject: [PATCH] value flow: fixed fp for nested assignments --- lib/valueflow.cpp | 17 +++++++++++------ test/testvalueflow.cpp | 5 +++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9a1d7199b..13e9a6603 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -90,12 +90,17 @@ static bool bailoutSelfAssignment(const Token * const tok) parent = parent->astParent(); // Assignment where lhs variable exists in rhs => return true - if (parent != NULL && - parent->astOperand2() == op && - parent->astOperand1() != NULL && - parent->str() == "=" && - parent->astOperand1()->str() == tok->str()) - return true; + if (parent != NULL && + parent->astOperand2() == op && + parent->astOperand1() != NULL && + parent->str() == "=") { + for (const Token *lhs = parent->astOperand1(); lhs; lhs = lhs->astOperand1()) { + if (lhs->varId() == tok->varId()) + return true; + if (lhs->astOperand2() && lhs->astOperand2()->varId() == tok->varId()) + return true; + } + } } return false; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 27274cef5..683d82634 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -111,6 +111,11 @@ private: "}"; ASSERT_EQUALS(false, testValueOfX(code, 2U, 65)); + code = "void f(int x) {\n" + " x = y = 2 + x;\n" + " if (x == 65);\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 2U, 65)); // guarding by && code = "void f(int x) {\n"