aboutsummaryrefslogtreecommitdiff
path: root/py/modstruct.c
diff options
context:
space:
mode:
authorTom McDermott <spon@wattwatchers.com.au>2019-08-05 15:15:28 +1000
committerDamien George <damien.p.george@gmail.com>2019-09-02 13:10:55 +1000
commit1022f9cc35564b216a4bcd7c65e8243c810a0ca9 (patch)
treebc2d7d12d447a63f6a4c1c9e0f862a616a9b9a80 /py/modstruct.c
parent12f13ee6346d8fd029fc2ecec06d50b5f7f6b252 (diff)
py/modstruct: Fix struct.unpack with unaligned offset of native type.
With this patch alignment is done relative to the start of the buffer that is being unpacked, not the raw pointer value, as per CPython. Fixes issue #3314.
Diffstat (limited to 'py/modstruct.c')
-rw-r--r--py/modstruct.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/py/modstruct.c b/py/modstruct.c
index 8617a8e0d..957e4917b 100644
--- a/py/modstruct.c
+++ b/py/modstruct.c
@@ -146,6 +146,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
}
p += offset;
}
+ byte *p_base = p;
// Check that the input buffer is big enough to unpack all the values
if (p + total_sz > end_p) {
@@ -164,7 +165,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
res->items[i++] = item;
} else {
while (cnt--) {
- item = mp_binary_get_val(fmt_type, *fmt, &p);
+ item = mp_binary_get_val(fmt_type, *fmt, p_base, &p);
res->items[i++] = item;
}
}