Skip to content

Commit 0f53d14

Browse files
committed
Check static array bounds of dynamic objects
Previously checking against malloc bounds and against statically-bounded arrays (e.g. int[2]) were mutually exclusive. This enables the static array bounds check even for dynamic objects. Fixes diffblue#239.
1 parent 972c4c7 commit 0f53d14

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

regression/cbmc/Pointer_byte_extract5/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.c
33
--bounds-check --32
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[main\.array_bounds\.5\] array.List upper bound in .*: FAILURE$
7-
^\*\* 1 of 9 failed (2 iterations)$
6+
array\.List dynamic object upper bound in p->List\[2\]: FAILURE
7+
\*\* 1 of 11 failed (2 iterations)
88
--
99
^warning: ignoring

src/analyses/goto_check.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,8 @@ void goto_checkt::bounds_check(
11931193
}
11941194
}
11951195

1196+
exprt type_matches_size=true_exprt();
1197+
11961198
if(ode.root_object().id()==ID_dereference)
11971199
{
11981200
const exprt &pointer=
@@ -1218,13 +1220,18 @@ void goto_checkt::bounds_check(
12181220

12191221
add_guarded_claim(
12201222
precond,
1221-
name+" upper bound",
1223+
name+" dynamic object upper bound",
12221224
"array bounds",
12231225
expr.find_source_location(),
12241226
expr,
12251227
guard);
12261228

1227-
return;
1229+
exprt type_size=size_of_expr(ode.root_object().type(), ns);
1230+
if(type_size.is_not_nil())
1231+
type_matches_size=
1232+
equal_exprt(
1233+
size,
1234+
typecast_exprt(type_size, size.type()));
12281235
}
12291236

12301237
const exprt &size=array_type.id()==ID_array ?
@@ -1257,7 +1264,7 @@ void goto_checkt::bounds_check(
12571264
inequality.op1().make_typecast(inequality.op0().type());
12581265

12591266
add_guarded_claim(
1260-
inequality,
1267+
implies_exprt(type_matches_size, inequality),
12611268
name+" upper bound",
12621269
"array bounds",
12631270
expr.find_source_location(),

0 commit comments

Comments
 (0)