diff --git a/py/objarray.c b/py/objarray.c index 58285c8660..da9dd528c5 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -439,6 +439,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value // TODO: alloc policy; at the moment we go conservative o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz); o->free = 0; + dest_items = o->items; } mp_seq_replace_slice_grow_inplace(dest_items, o->len, slice.start, slice.stop, src_items, src_len, len_adj, item_sz); diff --git a/tests/basics/bytearray_slice_assign.py b/tests/basics/bytearray_slice_assign.py index 3209e24d40..510e784da7 100644 --- a/tests/basics/bytearray_slice_assign.py +++ b/tests/basics/bytearray_slice_assign.py @@ -47,6 +47,9 @@ b = bytearray(2) b[2:] = bytearray(10) print(b) +b = bytearray(10) +b[:-1] = bytearray(500) +print(len(b), b[0], b[-1]) # Assignment of bytes to array slice b = bytearray(2)