| 436 | } |
| 437 | |
| 438 | bool 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 | |
| 479 | void CheckConditionImpl::duplicateCondition() |
| 480 | { |
nothing calls this directly
no test coverage detected