| 529 | } |
| 530 | |
| 531 | void CheckBufferOverrunImpl::pointerArithmeticError(const Token *tok, const Token *indexToken, const ValueFlow::Value *indexValue) |
| 532 | { |
| 533 | if (!tok) { |
| 534 | reportError(tok, Severity::portability, "pointerOutOfBounds", "Pointer arithmetic overflow.", CWE_POINTER_ARITHMETIC_OVERFLOW, Certainty::normal); |
| 535 | reportError(tok, Severity::portability, "pointerOutOfBoundsCond", "Pointer arithmetic overflow.", CWE_POINTER_ARITHMETIC_OVERFLOW, Certainty::normal); |
| 536 | return; |
| 537 | } |
| 538 | |
| 539 | std::string errmsg; |
| 540 | if (indexValue->condition) |
| 541 | errmsg = "Undefined behaviour, when '" + indexToken->expressionString() + "' is " + MathLib::toString(indexValue->intvalue) + " the pointer arithmetic '" + tok->expressionString() + "' is out of bounds."; |
| 542 | else |
| 543 | errmsg = "Undefined behaviour, pointer arithmetic '" + tok->expressionString() + "' is out of bounds."; |
| 544 | |
| 545 | reportError(getErrorPath(tok, indexValue, "Pointer arithmetic overflow"), |
| 546 | Severity::portability, |
| 547 | indexValue->condition ? "pointerOutOfBoundsCond" : "pointerOutOfBounds", |
| 548 | errmsg, |
| 549 | CWE_POINTER_ARITHMETIC_OVERFLOW, |
| 550 | indexValue->isInconclusive() ? Certainty::inconclusive : Certainty::normal); |
| 551 | } |
| 552 | |
| 553 | //--------------------------------------------------------------------------- |
| 554 |
no test coverage detected