Fixed #6537 (False positive badBitmaskCheck - error in valueflow)

This commit is contained in:
Daniel Marjamäki 2016-01-24 13:45:44 +01:00
parent a8416bfb16
commit 6faa637fc7
2 changed files with 9 additions and 2 deletions

View File

@ -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);

View File

@ -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());
}