Skip to content

Commit 520a42f

Browse files
committed
Hardwire maximum array size
1 parent 5361db1 commit 520a42f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/analyses/variable-sensitivity/full_array_abstract_object.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct eval_index_resultt
2424
mp_integer value;
2525
};
2626

27+
static mp_integer max_array_index = 10;
28+
2729
static eval_index_resultt eval_index(
2830
const exprt &expr,
2931
const abstract_environmentt &env,
@@ -453,5 +455,8 @@ static eval_index_resultt eval_index(
453455
mp_integer out_index;
454456
bool result = to_integer(to_constant_expr(value), out_index);
455457

458+
if(out_index > max_array_index)
459+
out_index = max_array_index;
460+
456461
return {!result, out_index};
457462
}

unit/analyses/variable-sensitivity/full_array_abstract_object/maximum_length.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ SCENARIO(
4646
symbol_tablet symbol_table;
4747
namespacet ns(symbol_table);
4848

49-
WHEN("Under maximum size, array = {1, 2, 3}")
49+
WHEN("array = {1, 2, 3}, writes under maximum size")
5050
{
5151
WHEN("array[3] = 4")
5252
{
@@ -92,4 +92,21 @@ SCENARIO(
9292
}
9393
}
9494
}
95+
WHEN("array = {1, 2, 3}, writes beyond maximum size mapped to max_size")
96+
{
97+
WHEN("array[99] = 4")
98+
{
99+
auto array = build_array({1, 2, 3}, environment, ns);
100+
101+
auto updated = write_array(array, 99, 4, environment, ns);
102+
103+
THEN("array equals {1, 2, 3, ..., [10] = 4}")
104+
{
105+
EXPECT_INDEX(updated, 0, 1, environment, ns);
106+
EXPECT_INDEX(updated, 1, 2, environment, ns);
107+
EXPECT_INDEX(updated, 2, 3, environment, ns);
108+
EXPECT_INDEX(updated, 10, 4, environment, ns);
109+
}
110+
}
111+
}
95112
}

0 commit comments

Comments
 (0)