| 406 | } |
| 407 | |
| 408 | void CheckBufferOverrunImpl::arrayIndexError(const Token* tok, |
| 409 | const std::vector<Dimension>& dimensions, |
| 410 | const std::vector<ValueFlow::Value>& indexes) |
| 411 | { |
| 412 | if (!tok) { |
| 413 | reportError(tok, Severity::error, "arrayIndexOutOfBounds", "Array 'arr[16]' accessed at index 16, which is out of bounds.", CWE_BUFFER_OVERRUN, Certainty::normal); |
| 414 | reportError(tok, Severity::warning, "arrayIndexOutOfBoundsCond", "Array 'arr[16]' accessed at index 16, which is out of bounds.", CWE_BUFFER_OVERRUN, Certainty::normal); |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | const Token *condition = nullptr; |
| 419 | const ValueFlow::Value *index = nullptr; |
| 420 | for (const ValueFlow::Value& indexValue : indexes) { |
| 421 | if (!indexValue.errorSeverity() && !mSettings.severity.isEnabled(Severity::warning)) |
| 422 | return; |
| 423 | if (indexValue.condition) |
| 424 | condition = indexValue.condition; |
| 425 | if (!index || !indexValue.errorPath.empty()) |
| 426 | index = &indexValue; |
| 427 | } |
| 428 | |
| 429 | reportError(getErrorPath(tok, index, "Array index out of bounds"), |
| 430 | index->errorSeverity() ? Severity::error : Severity::warning, |
| 431 | index->condition ? "arrayIndexOutOfBoundsCond" : "arrayIndexOutOfBounds", |
| 432 | arrayIndexMessage(tok, dimensions, indexes, condition), |
| 433 | CWE_BUFFER_OVERRUN, |
| 434 | index->isInconclusive() ? Certainty::inconclusive : Certainty::normal); |
| 435 | } |
| 436 | |
| 437 | void CheckBufferOverrunImpl::negativeIndexError(const Token* tok, |
| 438 | const std::vector<Dimension>& dimensions, |
no test coverage detected