py/modstruct: Fix struct.pack_into with unaligned offset of native type.

Following the same fix for unpack.
This commit is contained in:
Damien George
2019-09-02 12:57:51 +10:00
parent 1022f9cc35
commit 24c3e9b283
5 changed files with 14 additions and 6 deletions

View File

@@ -180,6 +180,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c
const char *fmt = mp_obj_str_get_str(fmt_in);
char fmt_type = get_fmt_type(&fmt);
byte *p_base = p;
size_t i;
for (i = 0; i < n_args;) {
mp_uint_t cnt = 1;
@@ -204,7 +205,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c
} else {
// If we run out of args then we just finish; CPython would raise struct.error
while (cnt-- && i < n_args) {
mp_binary_set_val(fmt_type, *fmt, args[i++], &p);
mp_binary_set_val(fmt_type, *fmt, args[i++], p_base, &p);
}
}
fmt++;