| 435 | } |
| 436 | |
| 437 | void 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 |
no test coverage detected