Skip to content

Commit b8b98d8

Browse files
Check if array cell totally contains object to extract
This is similar to what is done for struct. We check that the element is big enough (taking into account the offset) to totally contain the object we are trying to get.
1 parent 37a0fe0 commit b8b98d8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/util/pointer_offset_size.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,16 @@ optionalt<exprt> get_subexpression_at_offset(
694694
if(*target_size_bits <= *elem_size_bits)
695695
{
696696
const mp_integer elem_size_bytes = *elem_size_bits / 8;
697+
const auto offset_inside_elem = offset_bytes % elem_size_bytes;
698+
const auto target_size_bytes = *target_size_bits / 8;
699+
// only recurse if the cell completely contains the target
700+
if(offset_inside_elem + target_size_bytes > elem_size_bytes)
701+
return {};
702+
697703
return get_subexpression_at_offset(
698704
index_exprt(
699705
expr, from_integer(offset_bytes / elem_size_bytes, index_type())),
700-
offset_bytes % elem_size_bytes,
706+
offset_inside_elem,
701707
target_type_raw,
702708
ns);
703709
}

0 commit comments

Comments
 (0)