diff options
author | Damien George <damien.p.george@gmail.com> | 2019-09-02 12:57:51 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-09-02 13:14:16 +1000 |
commit | 24c3e9b283da26093ca653fc6b441042fedec135 (patch) | |
tree | 430cf3923afccc874902bebecb79f5b22572777c /py/binary.c | |
parent | 1022f9cc35564b216a4bcd7c65e8243c810a0ca9 (diff) |
py/modstruct: Fix struct.pack_into with unaligned offset of native type.
Following the same fix for unpack.
Diffstat (limited to 'py/binary.c')
-rw-r--r-- | py/binary.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/py/binary.c b/py/binary.c index 9810e4660..dfd25018c 100644 --- a/py/binary.c +++ b/py/binary.c @@ -250,14 +250,14 @@ void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t } } -void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **ptr) { +void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p_base, byte **ptr) { byte *p = *ptr; mp_uint_t align; size_t size = mp_binary_get_size(struct_type, val_type, &align); if (struct_type == '@') { - // Make pointer aligned - p = (byte*)MP_ALIGN(p, (size_t)align); + // Align p relative to p_base + p = p_base + (uintptr_t)MP_ALIGN(p - p_base, (size_t)align); if (MP_ENDIANNESS_LITTLE) { struct_type = '<'; } else { |