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

Method pointerArithmeticError

lib/checkbufferoverrun.cpp:531–551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

529}
530
531void 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

Callers 1

getErrorMessagesMethod · 0.45

Calls 4

reportErrorFunction · 0.70
toStringFunction · 0.70
expressionStringMethod · 0.45
isInconclusiveMethod · 0.45

Tested by

no test coverage detected