Fix 10413: FP arrayIndexOutOfBoundsCond after check (#3446)
This commit is contained in:
parent
045f21ee48
commit
98e22f6162
|
@ -7711,6 +7711,10 @@ static std::vector<ValueFlow::Value> isOutOfBoundsImpl(const ValueFlow::Value& s
|
|||
// TODO: Use a better way to decide if the variable in unconstrained
|
||||
if (!indexTok->variable() || !indexTok->variable()->isArgument())
|
||||
return {};
|
||||
if (std::any_of(indexTok->values().begin(), indexTok->values().end(), [&](const ValueFlow::Value& v) {
|
||||
return v.isSymbolicValue() && v.isPossible() && v.bound == ValueFlow::Value::Bound::Upper;
|
||||
}))
|
||||
return {};
|
||||
if (indexValue->bound != ValueFlow::Value::Bound::Lower)
|
||||
return {};
|
||||
if (size.bound == ValueFlow::Value::Bound::Lower)
|
||||
|
|
|
@ -135,6 +135,7 @@ private:
|
|||
TEST_CASE(array_index_56); // #10284
|
||||
TEST_CASE(array_index_57); // #10023
|
||||
TEST_CASE(array_index_58); // #7524
|
||||
TEST_CASE(array_index_59); // #10413
|
||||
TEST_CASE(array_index_multidim);
|
||||
TEST_CASE(array_index_switch_in_for);
|
||||
TEST_CASE(array_index_for_in_for); // FP: #2634
|
||||
|
@ -1652,6 +1653,18 @@ private:
|
|||
errout.str());
|
||||
}
|
||||
|
||||
void array_index_59()
|
||||
{
|
||||
check("long f(long b) {\n"
|
||||
" const long a[] = { 0, 1, };\n"
|
||||
" const long c = std::size(a);\n"
|
||||
" if (b < 0 || b >= c)\n"
|
||||
" return 0;\n"
|
||||
" return a[b];\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void array_index_multidim() {
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue