Skip to content

Commit 3bf5590

Browse files
committed
Make sure out-of-bounds accesses on managed CArrays don't do stupid things.
1 parent ec278ef commit 3bf5590

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/6model/reprs/CArray.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ static PMC * at_pos_complex(PARROT_INTERP, STable *st, void *data, INTVAL index)
231231

232232
if (body->managed) {
233233
/* We manage this array. */
234-
/* TODO: Will segfault if index is out of bounds. */
235-
return body->child_objs[index]? body->child_objs[index]: repr_data->elem_type;
234+
if (index < body->elems && body->child_objs[index])
235+
return body->child_objs[index];
236+
else
237+
return repr_data->elem_type;
236238
}
237239
else {
238240
/* Array comes from C. */

0 commit comments

Comments
 (0)