From ad74421526e36a0d5faba845c2edff31465b53b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 15 Oct 2016 19:09:50 +0200 Subject: [PATCH] Fixed #7756 (ValueFlow: fix bug in valueAfterAssign, same variable in lhs and rhs) --- lib/valueflow.cpp | 13 ++++++++++++- test/testvalueflow.cpp | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 14e3d11d9..e36d47ff6 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1674,7 +1674,18 @@ static void valueFlowAfterAssign(TokenList *tokenlist, SymbolDatabase* symboldat } } - valueFlowForward(tok, endOfVarScope, var, varid, values, constValue, tokenlist, errorLogger, settings); + // Skip RHS + const Token *nextExpression = tok->astOperand2(); + for (;;) { + if (nextExpression->astOperand2()) + nextExpression = nextExpression->astOperand2(); + else if (nextExpression->isUnaryPreOp()) + nextExpression = nextExpression->astOperand1(); + else break; + } + nextExpression = nextExpression->next(); + + valueFlowForward(const_cast(nextExpression), endOfVarScope, var, varid, values, constValue, tokenlist, errorLogger, settings); } } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index f986326e4..adec1c001 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -772,6 +772,13 @@ private: ASSERT_EQUALS(false, testValueOfX(code, 4U, 9)); ASSERT_EQUALS(true, testValueOfX(code, 4U, 8)); + code = "void x() {\n" + " int x = value ? 6 : 0;\n" + " x =\n" + " 1 + x;\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 4U, 7)); + code = "void f() {\n" " int x = 0;\n" " y = x += z;\n"