From dd9a1e890b32aae4f0b4aa00f90aeef07f8e8d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Nov 2018 17:13:23 +0100 Subject: [PATCH] valueFlowRightShift: Do not perform analysis when rhs is negative --- lib/valueflow.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 525d0d274..dc5aae8ac 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1156,6 +1156,10 @@ static void valueFlowRightShift(TokenList *tokenList) if (!tok->astOperand2()->hasKnownValue()) continue; + const MathLib::bigint rhsvalue = tok->astOperand2()->values().front().intvalue; + if (rhsvalue < 0) + continue; + if (!tok->astOperand1()->valueType() || !tok->astOperand1()->valueType()->isIntegral()) continue; @@ -1167,7 +1171,7 @@ static void valueFlowRightShift(TokenList *tokenList) continue; if (lhsmax < 0) continue; - if ((1 << tok->astOperand2()->values().front().intvalue) <= lhsmax) + if ((1 << rhsvalue) <= lhsmax) continue; ValueFlow::Value val(0);