diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2023-11-03 14:19:55 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-11-03 16:03:18 +1100 |
commit | b6a977848407a4ced45d118cf926bd915cc89dfb (patch) | |
tree | 372814eb7f8234ecc5ffc3a7112ad830e69784d9 /py/objtuple.c | |
parent | c85db05244ef6185fbb3c218c508ddd179830942 (diff) |
py/misc: Change sizeof to offsetof for variable-length alloc.
This fixes the case where e.g.
struct foo_t {
mp_obj_t x;
uint16_t y;
char buf[];
};
will have `sizeof(struct foo_t)==8`, but `offsetof(struct foo_t, buf)==6`.
When computing the size to allocate for `m_new_obj_var` we need to use
offsetof to avoid over-allocating. This is important especially when it
might cause it to spill over into another GC block.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/objtuple.c')
-rw-r--r-- | py/objtuple.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/py/objtuple.c b/py/objtuple.c index 0318a35db..969c488ee 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -264,7 +264,7 @@ void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items) { void mp_obj_tuple_del(mp_obj_t self_in) { assert(mp_obj_is_type(self_in, &mp_type_tuple)); mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in); - m_del_var(mp_obj_tuple_t, mp_obj_t, self->len, self); + m_del_var(mp_obj_tuple_t, items, mp_obj_t, self->len, self); } /******************************************************************************/ |