Skip to content

Commit c0c6402

Browse files
Update checkcondition.cpp [skip ci]
1 parent 33988e1 commit c0c6402

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lib/checkcondition.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,6 @@ void CheckConditionImpl::alwaysTrueFalse()
15361536
}
15371537
if (!tok->hasKnownIntValue())
15381538
continue;
1539-
const bool isZeroOrOne = (tok->getKnownIntValue() & ~MathLib::bigint(1)) == 0;
15401539
const Token* condition = nullptr;
15411540
{
15421541
// is this a condition..
@@ -1578,12 +1577,17 @@ void CheckConditionImpl::alwaysTrueFalse()
15781577
continue;
15791578
bool warnForNumber = false;
15801579
if (Token::Match(tok, "%num%|%bool%|%char%")) {
1580+
const bool isZeroOrOne = (tok->getKnownIntValue() >> 1) == 0;
15811581
warnForNumber = !isZeroOrOne && tok->tokType() == Token::eNumber && tok->astParent() == condition->astParent();
15821582
if (!warnForNumber)
15831583
continue;
15841584
}
1585-
if (Token::Match(tok, "! %num%|%bool%|%char%"))
1586-
continue;
1585+
if (Token::Match(tok, "! %num%|%bool%|%char%")) {
1586+
const bool isZeroOrOne = tok->next()->hasKnownIntValue() && (tok->next()->getKnownIntValue() >> 1) == 0;
1587+
warnForNumber = !isZeroOrOne && tok->next()->tokType() == Token::eNumber && tok->astParent() == condition->astParent();
1588+
if (!warnForNumber)
1589+
continue;
1590+
}
15871591
if (Token::Match(tok, "%oror%|&&")) {
15881592
bool bail = false;
15891593
for (const Token* op : { tok->astOperand1(), tok->astOperand2() }) {

0 commit comments

Comments
 (0)