@@ -3544,7 +3544,7 @@ static ElementCount findExcessiveDistance(const Token* firstTok,
35443544 const auto consider = [&](const ElementCount& candidate) {
35453545 if (!candidate)
35463546 return ;
3547- if (candidate.count <= 0 || candidate. count <= available)
3547+ if (candidate.count <= available)
35483548 return ; // the access is within bounds
35493549 excessive.consider (candidate);
35503550 };
@@ -3636,9 +3636,9 @@ void CheckStlImpl::algorithmOutOfBounds()
36363636 nameTok,
36373637 " copy|move|swap_ranges|transform|replace_copy|replace_copy_if|reverse_copy|equal|mismatch|is_permutation|partial_sum|adjacent_difference|inner_product (" );
36383638 // ..or at most last1-first1 times, depending on the values in the input range..
3639- const bool atMost = Token::Match (nameTok, " copy_if|remove_copy|remove_copy_if|unique_copy (" );
3639+ const bool atMost = !exact && Token::Match (nameTok, " copy_if|remove_copy|remove_copy_if|unique_copy (" );
36403640 // ..or accessing their iterator arguments as many times as the count argument says
3641- const bool countBased = Token::Match (nameTok, " copy_n|fill_n|generate_n (" );
3641+ const bool countBased = !exact && !atMost && Token::Match (nameTok, " copy_n|fill_n|generate_n (" );
36423642 if (!exact && !atMost && !countBased)
36433643 continue ;
36443644 if (atMost && !mSettings .certainty .isEnabled (Certainty::inconclusive))
@@ -3716,7 +3716,6 @@ void CheckStlImpl::algorithmOutOfBounds()
37163716 sourceCount.count ,
37173717 available.count ,
37183718 pathValue,
3719- conditionValue ? conditionValue->condition : nullptr ,
37203719 atMost,
37213720 atMost || inconclusiveValues);
37223721 }
@@ -3729,10 +3728,10 @@ void CheckStlImpl::algorithmOutOfBoundsError(const Token* tok,
37293728 MathLib::bigint accessed,
37303729 MathLib::bigint available,
37313730 const ValueFlow::Value* value,
3732- const Token* condition,
37333731 bool mayAccessFewer,
37343732 bool inconclusive)
37353733{
3734+ const Token* const condition = value ? value->condition : nullptr ;
37363735 const std::string iterExpr = tok ? tok->expressionString () : " it" ;
37373736 const std::string accessedStr = MathLib::toString (accessed) + (accessed == 1 ? " element" : " elements" );
37383737 const std::string availableStr = MathLib::toString (available) + (available == 1 ? " element is" : " elements are" );
@@ -3901,7 +3900,7 @@ void CheckStl::getErrorMessages(ErrorLogger& errorLogger, const Settings& settin
39013900 c.dereferenceInvalidIteratorError (nullptr , " i" );
39023901 // TODO: derefInvalidIteratorRedundantCheck
39033902 c.eraseIteratorOutOfBoundsError (nullptr , nullptr );
3904- c.algorithmOutOfBoundsError (nullptr , " std::copy" , 10 , 6 , nullptr , nullptr , false , false );
3903+ c.algorithmOutOfBoundsError (nullptr , " std::copy" , 10 , 6 , nullptr , false , false );
39053904 c.useStlAlgorithmError (nullptr , " " );
39063905 c.knownEmptyContainerError (nullptr , " " );
39073906 c.globalLockGuardError (nullptr );
0 commit comments