From 6faa637fc7fa40217ed8a1cd2826718d73f834cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 24 Jan 2016 13:45:44 +0100 Subject: [PATCH] Fixed #6537 (False positive badBitmaskCheck - error in valueflow) --- lib/checkcondition.cpp | 4 ++-- test/testcondition.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index 0d2627f1b..decf3909a 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -256,8 +256,8 @@ void CheckCondition::checkBadBitmaskCheck() (parent->str() == "(" && Token::Match(parent->astOperand1(), "if|while")) || (parent->str() == "return" && parent->astOperand1() == tok && inBooleanFunction(tok)); - const bool isTrue = (tok->astOperand1()->values.size() == 1 && tok->astOperand1()->values.front().intvalue != 0 && !tok->astOperand1()->values.front().conditional) || - (tok->astOperand2()->values.size() == 1 && tok->astOperand2()->values.front().intvalue != 0 && !tok->astOperand2()->values.front().conditional); + const bool isTrue = (tok->astOperand1()->values.size() == 1 && tok->astOperand1()->values.front().intvalue != 0 && tok->astOperand1()->values.front().isKnown()) || + (tok->astOperand2()->values.size() == 1 && tok->astOperand2()->values.front().intvalue != 0 && tok->astOperand2()->values.front().isKnown()); if (isBoolean && isTrue) badBitmaskCheckError(tok); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index e7a0f48df..e3ff4d4b2 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -581,6 +581,13 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("void f(unsigned a, unsigned b) {\n" + " unsigned cmd1 = b & 0x0F;\n" + " if (cmd1 | a) {\n" + " if (b == 0x0C) {}\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); }