@@ -127,6 +127,16 @@ static const Token* getContainerFromSize(const Library::Container* container, co
127127 return nullptr ;
128128}
129129
130+ // A value that out of bounds analysis can use: not impossible, and inconclusive only when enabled
131+ static bool isUsableValue (const ValueFlow::Value& value, const Settings& settings)
132+ {
133+ if (value.isImpossible ())
134+ return false ;
135+ if (value.isInconclusive () && !settings.certainty .isEnabled (Certainty::inconclusive))
136+ return false ;
137+ return true ;
138+ }
139+
130140void CheckStlImpl::outOfBounds ()
131141{
132142 logChecker (" CheckStl::outOfBounds" );
@@ -148,9 +158,7 @@ void CheckStlImpl::outOfBounds()
148158 for (const ValueFlow::Value &value : tok->values ()) {
149159 if (!value.isContainerSizeValue ())
150160 continue ;
151- if (value.isImpossible ())
152- continue ;
153- if (value.isInconclusive () && !mSettings .certainty .isEnabled (Certainty::inconclusive))
161+ if (!isUsableValue (value, mSettings ))
154162 continue ;
155163 if (!value.errorSeverity () && !mSettings .severity .isEnabled (Severity::warning))
156164 continue ;
@@ -2482,8 +2490,6 @@ void CheckStlImpl::checkDereferenceInvalidIterator()
24822490
24832491void CheckStlImpl::checkDereferenceInvalidIterator2 ()
24842492{
2485- const bool printInconclusive = (mSettings .certainty .isEnabled (Certainty::inconclusive));
2486-
24872493 logChecker (" CheckStl::checkDereferenceInvalidIterator2" );
24882494
24892495 for (const Token *tok = mTokenizer ->tokens (); tok; tok = tok->next ()) {
@@ -2497,19 +2503,13 @@ void CheckStlImpl::checkDereferenceInvalidIterator2()
24972503
24982504 std::vector<ValueFlow::Value> contValues;
24992505 std::copy_if (tok->values ().cbegin (), tok->values ().cend (), std::back_inserter (contValues), [&](const ValueFlow::Value& value) {
2500- if (value.isImpossible ())
2501- return false ;
2502- if (!printInconclusive && value.isInconclusive ())
2503- return false ;
2504- return value.isContainerSizeValue ();
2506+ return isUsableValue (value, mSettings ) && value.isContainerSizeValue ();
25052507 });
25062508
25072509
25082510 // Can iterator point to END or before START?
25092511 for (const ValueFlow::Value& value:tok->values ()) {
2510- if (value.isImpossible ())
2511- continue ;
2512- if (!printInconclusive && value.isInconclusive ())
2512+ if (!isUsableValue (value, mSettings ))
25132513 continue ;
25142514 if (!value.isIteratorValue ())
25152515 continue ;
@@ -3402,15 +3402,6 @@ namespace {
34023402 };
34033403}
34043404
3405- static bool isUsableValue (const ValueFlow::Value& value, const Settings& settings)
3406- {
3407- if (value.isImpossible ())
3408- return false ;
3409- if (value.isInconclusive () && !settings.certainty .isEnabled (Certainty::inconclusive))
3410- return false ;
3411- return true ;
3412- }
3413-
34143405// Get the first ValueFlow value of a token matching the predicate, preferring known values
34153406template <class Predicate >
34163407static const ValueFlow::Value* selectPreferredValue (const Token* tok, const Predicate& pred)
0 commit comments