MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / isOverlappingCond

Method isOverlappingCond

lib/checkcondition.cpp:438–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

436}
437
438bool CheckConditionImpl::isOverlappingCond(const Token * const cond1, const Token * const cond2, bool pure) const
439{
440 if (!cond1 || !cond2)
441 return false;
442
443 // same expressions
444 if (isSameExpression(true, cond1, cond2, mSettings, pure, false))
445 return true;
446
447 // bitwise overlap for example 'x&7' and 'x==1'
448 if (cond1->str() == "&" && cond1->astOperand1() && cond2->astOperand2()) {
449 const Token *expr1 = cond1->astOperand1();
450 const Token *num1 = cond1->astOperand2();
451 if (!num1) // unary operator&
452 return false;
453 if (!num1->isNumber())
454 std::swap(expr1,num1);
455 if (!num1->isNumber() || MathLib::isNegative(num1->str()))
456 return false;
457
458 if (!Token::Match(cond2, "&|==") || !cond2->astOperand1() || !cond2->astOperand2())
459 return false;
460 const Token *expr2 = cond2->astOperand1();
461 const Token *num2 = cond2->astOperand2();
462 if (!num2->isNumber())
463 std::swap(expr2,num2);
464 if (!num2->isNumber() || MathLib::isNegative(num2->str()))
465 return false;
466
467 if (!isSameExpression(true, expr1, expr2, mSettings, pure, false))
468 return false;
469
470 const MathLib::bigint value1 = MathLib::toBigNumber(num1);
471 const MathLib::bigint value2 = MathLib::toBigNumber(num2);
472 if (cond2->str() == "&")
473 return ((value1 & value2) == value2);
474 return ((value1 & value2) > 0);
475 }
476 return false;
477}
478
479void CheckConditionImpl::duplicateCondition()
480{

Callers

nothing calls this directly

Calls 6

isSameExpressionFunction · 0.85
isNegativeFunction · 0.85
astOperand1Method · 0.80
astOperand2Method · 0.80
swapFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected