| 386 | } |
| 387 | |
| 388 | static std::string arrayIndexMessage(const Token* tok, |
| 389 | const std::vector<Dimension>& dimensions, |
| 390 | const std::vector<ValueFlow::Value>& indexValues, |
| 391 | const Token* condition) |
| 392 | { |
| 393 | auto add_dim = [](const std::string &s, const Dimension &dim) { |
| 394 | return s + "[" + MathLib::toString(dim.num) + "]"; |
| 395 | }; |
| 396 | const std::string array = std::accumulate(dimensions.cbegin(), dimensions.cend(), tok->astOperand1()->expressionString(), std::move(add_dim)); |
| 397 | |
| 398 | std::ostringstream errmsg; |
| 399 | if (condition) |
| 400 | errmsg << ValueFlow::eitherTheConditionIsRedundant(condition) |
| 401 | << " or the array '" << array << "' is accessed at index " << stringifyIndexes(tok->astOperand1()->expressionString(), indexValues) << ", which is out of bounds."; |
| 402 | else |
| 403 | errmsg << "Array '" << array << "' accessed at index " << stringifyIndexes(tok->astOperand1()->expressionString(), indexValues) << ", which is out of bounds."; |
| 404 | |
| 405 | return errmsg.str(); |
| 406 | } |
| 407 | |
| 408 | void CheckBufferOverrunImpl::arrayIndexError(const Token* tok, |
| 409 | const std::vector<Dimension>& dimensions, |
no test coverage detected