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

Method negativeIndexError

lib/checkbufferoverrun.cpp:437–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435}
436
437void CheckBufferOverrunImpl::negativeIndexError(const Token* tok,
438 const std::vector<Dimension>& dimensions,
439 const std::vector<ValueFlow::Value>& indexes)
440{
441 if (!tok) {
442 reportError(tok, Severity::error, "negativeIndex", "Negative array index", CWE_BUFFER_UNDERRUN, Certainty::normal);
443 return;
444 }
445
446 const Token *condition = nullptr;
447 const ValueFlow::Value *negativeValue = nullptr;
448 for (const ValueFlow::Value& indexValue : indexes) {
449 if (!indexValue.errorSeverity() && !mSettings.severity.isEnabled(Severity::warning))
450 return;
451 if (indexValue.condition)
452 condition = indexValue.condition;
453 if (!negativeValue || !indexValue.errorPath.empty())
454 negativeValue = &indexValue;
455 }
456
457 reportError(getErrorPath(tok, negativeValue, "Negative array index"),
458 negativeValue->errorSeverity() ? Severity::error : Severity::warning,
459 "negativeIndex",
460 arrayIndexMessage(tok, dimensions, indexes, condition),
461 CWE_BUFFER_UNDERRUN,
462 negativeValue->isInconclusive() ? Certainty::inconclusive : Certainty::normal);
463}
464
465//---------------------------------------------------------------------------
466

Callers 1

getErrorMessagesMethod · 0.45

Calls 5

arrayIndexMessageFunction · 0.85
reportErrorFunction · 0.70
isEnabledMethod · 0.45
emptyMethod · 0.45
isInconclusiveMethod · 0.45

Tested by

no test coverage detected