@@ -221,7 +221,7 @@ static bool getDimensionsEtc(const Token * const arrayToken, const Settings &set
221221 return ChildrenToVisit::op1_and_op2;
222222 });
223223 }
224- } else if (const Token *stringLiteral = array->getValueTokenMinStrSize (settings, &path)) {
224+ } else if (const Token *stringLiteral = array->getValueTokenMinStrSize (settings, &path, &errorPath )) {
225225 Dimension dim;
226226 dim.tok = nullptr ;
227227 dim.num = Token::getStrArraySize (stringLiteral);
@@ -360,7 +360,7 @@ void CheckBufferOverrunImpl::arrayIndex()
360360 const std::vector<ValueFlow::Value>& indexValues =
361361 getOverrunIndexValues (tok, tok->astOperand1 (), dimensions, indexTokens, path);
362362 if (!indexValues.empty ())
363- arrayIndexError (tok, dimensions, indexValues);
363+ arrayIndexError (tok, dimensions, indexValues, std::move (errorPath) );
364364 }
365365
366366 // Negative index
@@ -421,7 +421,8 @@ static std::string arrayIndexMessage(const Token* tok,
421421
422422void CheckBufferOverrunImpl::arrayIndexError (const Token* tok,
423423 const std::vector<Dimension>& dimensions,
424- const std::vector<ValueFlow::Value>& indexes)
424+ const std::vector<ValueFlow::Value>& indexes,
425+ ErrorPath errorPath)
425426{
426427 if (!tok) {
427428 reportError (tok, Severity::error, " arrayIndexOutOfBounds" , " Array 'arr[16]' accessed at index 16, which is out of bounds." , CWE_BUFFER_OVERRUN , Certainty::normal);
@@ -440,7 +441,10 @@ void CheckBufferOverrunImpl::arrayIndexError(const Token* tok,
440441 index = &indexValue;
441442 }
442443
443- reportError (getErrorPath (tok, index, " Array index out of bounds" ),
444+ const ErrorPath errorPathTok = getErrorPath (tok, index, " Array index out of bounds" );
445+ errorPath.insert (errorPath.end (), errorPathTok.begin (), errorPathTok.end ());
446+
447+ reportError (errorPath,
444448 index->errorSeverity () ? Severity::error : Severity::warning,
445449 index->condition ? " arrayIndexOutOfBoundsCond" : " arrayIndexOutOfBounds" ,
446450 arrayIndexMessage (tok, dimensions, indexes, condition),
@@ -1342,7 +1346,7 @@ void CheckBufferOverrun::runChecks(const Tokenizer &tokenizer, ErrorLogger& erro
13421346void CheckBufferOverrun::getErrorMessages (ErrorLogger& errorLogger, const Settings &settings) const
13431347{
13441348 CheckBufferOverrunImpl c (nullptr , settings, errorLogger);
1345- c.arrayIndexError (nullptr , std::vector<Dimension>(), std::vector<ValueFlow::Value>());
1349+ c.arrayIndexError (nullptr , std::vector<Dimension>(), std::vector<ValueFlow::Value>(), {} );
13461350 c.pointerArithmeticError (nullptr , nullptr , nullptr );
13471351 c.negativeIndexError (nullptr , std::vector<Dimension>(), std::vector<ValueFlow::Value>());
13481352 c.arrayIndexThenCheckError (nullptr , " i" );
0 commit comments