@@ -2503,11 +2503,13 @@ void CheckStlImpl::checkDereferenceInvalidIterator2()
25032503 continue ;
25042504
25052505 std::vector<ValueFlow::Value> contValues;
2506- std::copy_if (tok->values ().cbegin (), tok->values ().cend (), std::back_inserter (contValues), [&](const ValueFlow::Value& value) {
2506+ std::copy_if (tok->values ().cbegin (),
2507+ tok->values ().cend (),
2508+ std::back_inserter (contValues),
2509+ [&](const ValueFlow::Value& value) {
25072510 return isUsableValue (value, mSettings ) && value.isContainerSizeValue ();
25082511 });
25092512
2510-
25112513 // Can iterator point to END or before START?
25122514 for (const ValueFlow::Value& value:tok->values ()) {
25132515 if (!isUsableValue (value, mSettings ))
@@ -3381,9 +3383,9 @@ void CheckStlImpl::eraseIteratorOutOfBounds()
33813383}
33823384
33833385namespace {
3384- // An iterator position described by the ValueFlow values attached to the iterator expression
3386+ // An iterator position described by the ValueFlow values attached to the iterator expression
33853387 struct IteratorPosition {
3386- const ValueFlow::Value* value = nullptr ; // ITERATOR_START or ITERATOR_END value
3388+ const ValueFlow::Value* value = nullptr ; // ITERATOR_START or ITERATOR_END value
33873389 const ValueFlow::Value* sizeValue = nullptr ; // container size value with the same path, if available
33883390 bool fromEnd () const {
33893391 return value->isIteratorEndValue ();
@@ -3393,7 +3395,7 @@ namespace {
33933395 }
33943396 };
33953397
3396- // A number of elements together with the ValueFlow values it was derived from
3398+ // A number of elements together with the ValueFlow values it was derived from
33973399 struct ElementCount {
33983400 MathLib::bigint count = 0 ;
33993401 std::vector<const ValueFlow::Value*> values;
@@ -3402,21 +3404,21 @@ namespace {
34023404 }
34033405 };
34043406
3405- // The best candidate proving an out of bounds access, preferring proofs without possible values
3407+ // The best candidate proving an out of bounds access, preferring proofs without possible values
34063408 struct BestCandidate {
34073409 ElementCount best;
34083410 bool certain = false ;
3409- void consider (const ElementCount& candidate) {
3410- const bool candidateCertain = std::none_of (candidate. values . cbegin (),
3411- candidate. values . cend (),
3412- std::mem_fn (&ValueFlow::Value::isPossible));
3411+ void consider (const ElementCount& candidate)
3412+ {
3413+ const bool candidateCertain =
3414+ std::none_of (candidate. values . cbegin (), candidate. values . cend (), std::mem_fn (&ValueFlow::Value::isPossible));
34133415 if (best && (certain || !candidateCertain))
34143416 return ;
34153417 best = candidate;
34163418 certain = candidateCertain;
34173419 }
34183420 };
3419- }
3421+ } // namespace
34203422
34213423// Get the first ValueFlow value of a token matching the predicate, preferring known values
34223424template <class Predicate >
@@ -3462,15 +3464,15 @@ static ElementCount getIteratorDistance(const IteratorPosition& first, const Ite
34623464 return distance;
34633465 if (first.fromEnd () == last.fromEnd ()) { // the container size cancels out
34643466 distance.count = last.value ->intvalue - first.value ->intvalue ;
3465- distance.values = { first.value , last.value };
3467+ distance.values = {first.value , last.value };
34663468 return distance;
34673469 }
34683470 const IteratorPosition& endPosition = first.fromEnd () ? first : last;
34693471 if (!endPosition.sizeValue || endPosition.sizeValue ->bound != ValueFlow::Value::Bound::Point)
34703472 return distance;
34713473 const MathLib::bigint endIndex = endPosition.sizeValue ->intvalue + endPosition.value ->intvalue ;
34723474 distance.count = last.fromEnd () ? endIndex - first.value ->intvalue : last.value ->intvalue - endIndex;
3473- distance.values = { first.value , last.value , endPosition.sizeValue };
3475+ distance.values = {first.value , last.value , endPosition.sizeValue };
34743476 return distance;
34753477}
34763478
@@ -3483,14 +3485,14 @@ static ElementCount getAvailableSpace(const IteratorPosition& position)
34833485 return available;
34843486 if (position.fromEnd ()) { // the container size cancels out
34853487 available.count = -position.value ->intvalue ;
3486- available.values = { position.value };
3488+ available.values = {position.value };
34873489 return available;
34883490 }
34893491 // the container size could be larger, which would make more elements available
34903492 if (!position.sizeValue || position.sizeValue ->bound == ValueFlow::Value::Bound::Lower)
34913493 return available;
34923494 available.count = position.sizeValue ->intvalue - position.value ->intvalue ;
3493- available.values = { position.value , position.sizeValue };
3495+ available.values = {position.value , position.sizeValue };
34943496 return available;
34953497}
34963498
@@ -3626,8 +3628,8 @@ static const ValueFlow::Value* getCountValue(const Token* tok, const Settings& s
36263628void CheckStlImpl::algorithmOutOfBounds ()
36273629{
36283630 logChecker (" CheckStl::algorithmOutOfBounds" );
3629- for (const Scope * function : mTokenizer ->getSymbolDatabase ()->functionScopes ) {
3630- for (const Token * tok = function->bodyStart ; tok != function->bodyEnd ; tok = tok->next ()) {
3631+ for (const Scope* function : mTokenizer ->getSymbolDatabase ()->functionScopes ) {
3632+ for (const Token* tok = function->bodyStart ; tok != function->bodyEnd ; tok = tok->next ()) {
36313633 if (!Token::Match (tok, " std :: %name% (" ))
36323634 continue ;
36333635 const Token* const nameTok = tok->tokAt (2 );
@@ -3665,8 +3667,10 @@ void CheckStlImpl::algorithmOutOfBounds()
36653667 const ValueFlow::Value lastLifetime = getLifetimeIteratorValue (args[1 ]);
36663668 if (!firstLifetime.tokvalue || !lastLifetime.tokvalue )
36673669 continue ;
3668- if (!isSameIteratorContainerExpression (
3669- firstLifetime.tokvalue , lastLifetime.tokvalue , mSettings , firstLifetime.lifetimeKind ))
3670+ if (!isSameIteratorContainerExpression (firstLifetime.tokvalue ,
3671+ lastLifetime.tokvalue ,
3672+ mSettings ,
3673+ firstLifetime.lifetimeKind ))
36703674 continue ;
36713675 const IteratorPosition first = getIteratorPosition (args[0 ], mSettings );
36723676 const IteratorPosition last = getIteratorPosition (args[1 ], mSettings );
@@ -3677,7 +3681,7 @@ void CheckStlImpl::algorithmOutOfBounds()
36773681 iterArgs.push_back (args[3 ]); // binary transform also writes through the fourth argument
36783682 }
36793683 if (accessed.count <= 0 )
3680- accessed = ElementCount (); // there is no preferred source access count
3684+ accessed = ElementCount (); // there is no preferred source access count
36813685 for (const Token* const iterArg : iterArgs) {
36823686 // check the preferred source access count against all destination values..
36833687 ElementCount sourceCount = accessed;
@@ -3693,9 +3697,10 @@ void CheckStlImpl::algorithmOutOfBounds()
36933697 available = getAvailableSpace (dest);
36943698 if (!available || available.count < 0 )
36953699 continue ;
3696- sourceCount = countBased
3697- ? findExcessiveCount (args[1 ], available.count , dest.value ->path , mSettings )
3698- : findExcessiveDistance (args[0 ], args[1 ], available.count , dest.value ->path , mSettings );
3700+ sourceCount =
3701+ countBased
3702+ ? findExcessiveCount (args[1 ], available.count , dest.value ->path , mSettings )
3703+ : findExcessiveDistance (args[0 ], args[1 ], available.count , dest.value ->path , mSettings );
36993704 if (!sourceCount || bothSidesPossible (sourceCount, available))
37003705 continue ;
37013706 }
0 commit comments