Skip to content

Commit 77f85db

Browse files
committed
py/objarray: Fix array slice assignment when array is reallocated.
Addresses issue adafruit#1898.
1 parent 06b3984 commit 77f85db

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

py/objarray.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
439439
// TODO: alloc policy; at the moment we go conservative
440440
o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz);
441441
o->free = 0;
442+
dest_items = o->items;
442443
}
443444
mp_seq_replace_slice_grow_inplace(dest_items, o->len,
444445
slice.start, slice.stop, src_items, src_len, len_adj, item_sz);

tests/basics/bytearray_slice_assign.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
b[2:] = bytearray(10)
4848
print(b)
4949

50+
b = bytearray(10)
51+
b[:-1] = bytearray(500)
52+
print(len(b), b[0], b[-1])
5053

5154
# Assignment of bytes to array slice
5255
b = bytearray(2)

0 commit comments

Comments
 (0)