Skip to content

Commit f1ba660

Browse files
author
Your Name
committed
Some cleanup
1 parent 702a29c commit f1ba660

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

lib/checkstl.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "checknullpointer.h"
3636

3737
#include <algorithm>
38+
#include <functional>
3839
#include <initializer_list>
3940
#include <iterator>
4041
#include <list>
@@ -3478,11 +3479,6 @@ static ElementCount getAvailableSpace(const IteratorPosition& position)
34783479
return available;
34793480
}
34803481

3481-
static bool isPossibleValue(const ValueFlow::Value* value)
3482-
{
3483-
return value->isPossible();
3484-
}
3485-
34863482
// Find iterator values and paired container sizes of the iterator that prove accessing <accessed>
34873483
// elements to be out of bounds, preferring a proof that does not rely on possible values
34883484
static ElementCount findInsufficientSpace(const Token* tok,
@@ -3499,7 +3495,8 @@ static ElementCount findInsufficientSpace(const Token* tok,
34993495
return;
35003496
if (candidate.count < 0 || accessed <= candidate.count)
35013497
return; // the space is sufficient
3502-
const bool certain = std::none_of(candidate.values.cbegin(), candidate.values.cend(), isPossibleValue);
3498+
const bool certain =
3499+
std::none_of(candidate.values.cbegin(), candidate.values.cend(), std::mem_fn(&ValueFlow::Value::isPossible));
35033500
if (best && (bestIsCertain || !certain))
35043501
return;
35053502
best = candidate;
@@ -3561,16 +3558,16 @@ void CheckStlImpl::algorithmOutOfBounds()
35613558
if (args.size() < 3)
35623559
continue;
35633560
ElementCount accessed;
3564-
std::vector<std::size_t> iterArgs;
3561+
std::vector<const Token*> iterArgs;
35653562
if (countBased) {
35663563
const ValueFlow::Value* countValue = getCountValue(args[1], mSettings);
35673564
if (!countValue)
35683565
continue;
35693566
accessed.count = countValue->intvalue;
35703567
accessed.values.push_back(countValue);
3571-
iterArgs.push_back(0);
3568+
iterArgs.push_back(args[0]);
35723569
if (Token::simpleMatch(nameTok, "copy_n"))
3573-
iterArgs.push_back(2); // copy_n also writes through the third argument
3570+
iterArgs.push_back(args[2]); // copy_n also writes through the third argument
35743571
} else {
35753572
// two-range overloads taking a last2 iterator do not access the second range out of bounds
35763573
if (Token::Match(nameTok, "equal|mismatch|is_permutation") && args.size() >= 4 && astIsIterator(args[3]))
@@ -3592,20 +3589,21 @@ void CheckStlImpl::algorithmOutOfBounds()
35923589
accessed = getIteratorDistance(first, last);
35933590
if (!accessed)
35943591
continue;
3595-
iterArgs.push_back(2);
3592+
iterArgs.push_back(args[2]);
35963593
if (Token::simpleMatch(nameTok, "transform") && args.size() == 5)
3597-
iterArgs.push_back(3); // binary transform also writes through the fourth argument
3594+
iterArgs.push_back(args[3]); // binary transform also writes through the fourth argument
35983595
}
35993596
if (accessed.count <= 0)
36003597
continue;
36013598
const MathLib::bigint sourcePath = accessed.values.front()->path;
3602-
for (const std::size_t argnr : iterArgs) {
3603-
const ElementCount available = findInsufficientSpace(args[argnr], accessed.count, sourcePath, mSettings);
3599+
for (const Token* const iterArg : iterArgs) {
3600+
const ElementCount available = findInsufficientSpace(iterArg, accessed.count, sourcePath, mSettings);
36043601
if (!available)
36053602
continue;
36063603
// do not warn when the values on both sides are only possible
3607-
if (std::any_of(accessed.values.cbegin(), accessed.values.cend(), isPossibleValue) &&
3608-
std::any_of(available.values.cbegin(), available.values.cend(), isPossibleValue))
3604+
const auto isPossible = std::mem_fn(&ValueFlow::Value::isPossible);
3605+
if (std::any_of(accessed.values.cbegin(), accessed.values.cend(), isPossible) &&
3606+
std::any_of(available.values.cbegin(), available.values.cend(), isPossible))
36093607
continue;
36103608
const ValueFlow::Value* conditionValue = nullptr;
36113609
bool inconclusiveValues = false;
@@ -3619,7 +3617,7 @@ void CheckStlImpl::algorithmOutOfBounds()
36193617
if (conditionValue && !mSettings.severity.isEnabled(Severity::warning))
36203618
continue;
36213619
const ValueFlow::Value* pathValue = conditionValue ? conditionValue : available.values.back();
3622-
algorithmOutOfBoundsError(args[argnr],
3620+
algorithmOutOfBoundsError(iterArg,
36233621
"std::" + nameTok->str(),
36243622
accessed.count,
36253623
available.count,

0 commit comments

Comments
 (0)