py: Use memmove instead of memcpy when appropriate.
Found this bug by running unix/ tests with DEBUG=1 enabled when compiling.
This commit is contained in:
parent
02d95d7ce9
commit
17ae2395c2
4
py/obj.h
4
py/obj.h
|
@ -585,8 +585,8 @@ mp_obj_t mp_seq_extract_slice(uint len, const mp_obj_t *seq, mp_bound_slice_t *i
|
|||
#define mp_seq_replace_slice_no_grow(dest, dest_len, beg, end, slice, slice_len, item_t) \
|
||||
/*printf("memcpy(%p, %p, %d)\n", dest + beg, slice, slice_len * sizeof(item_t));*/ \
|
||||
memcpy(dest + beg, slice, slice_len * sizeof(item_t)); \
|
||||
/*printf("memcpy(%p, %p, %d)\n", dest + (beg + slice_len), dest + end, (dest_len - end) * sizeof(item_t));*/ \
|
||||
memcpy(dest + (beg + slice_len), dest + end, (dest_len - end) * sizeof(item_t));
|
||||
/*printf("memmove(%p, %p, %d)\n", dest + (beg + slice_len), dest + end, (dest_len - end) * sizeof(item_t));*/ \
|
||||
memmove(dest + (beg + slice_len), dest + end, (dest_len - end) * sizeof(item_t));
|
||||
|
||||
#define mp_seq_replace_slice_grow_inplace(dest, dest_len, beg, end, slice, slice_len, len_adj, item_t) \
|
||||
/*printf("memmove(%p, %p, %d)\n", dest + beg + len_adj, dest + beg, (dest_len - beg) * sizeof(item_t));*/ \
|
||||
|
|
|
@ -274,7 +274,7 @@ STATIC mp_obj_t list_pop(uint n_args, const mp_obj_t *args) {
|
|||
uint index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
|
||||
mp_obj_t ret = self->items[index];
|
||||
self->len -= 1;
|
||||
memcpy(self->items + index, self->items + index + 1, (self->len - index) * sizeof(mp_obj_t));
|
||||
memmove(self->items + index, self->items + index + 1, (self->len - index) * sizeof(mp_obj_t));
|
||||
// Clear stale pointer from slot which just got freed to prevent GC issues
|
||||
self->items[self->len] = MP_OBJ_NULL;
|
||||
if (self->alloc > LIST_MIN_ALLOC && self->alloc > 2 * self->len) {
|
||||
|
|
|
@ -567,7 +567,7 @@ STATIC mp_obj_t str_rsplit(uint n_args, const mp_obj_t *args) {
|
|||
if (idx != 0) {
|
||||
// We split less parts than split limit, now go cleanup surplus
|
||||
int used = org_splits + 1 - idx;
|
||||
memcpy(res->items, &res->items[idx], used * sizeof(mp_obj_t));
|
||||
memmove(res->items, &res->items[idx], used * sizeof(mp_obj_t));
|
||||
mp_seq_clear(res->items, used, res->alloc, sizeof(*res->items));
|
||||
res->len = used;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue