diff options
author | Damien George <damien.p.george@gmail.com> | 2017-09-01 10:10:51 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-09-01 10:10:51 +1000 |
commit | 793d826d9df67c3f544505beda63ca36d8dfa1c4 (patch) | |
tree | 7d5fe63db397e3fc7deec311b1f4b268c0d117a5 /py/modstruct.c | |
parent | b349479a49aab440b2f38fc6e45b3df4bf7a1aa7 (diff) |
py/modstruct: In struct.pack, stop converting if there are no args left.
This patch makes a repeat counter behave the same as repeating the
typecode, when there are not enough args. For example:
struct.pack('2I', 1) now behave the same as struct.pack('II', 1).
Diffstat (limited to 'py/modstruct.c')
-rw-r--r-- | py/modstruct.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/py/modstruct.c b/py/modstruct.c index 1daa33338..0d4a45f6b 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -206,7 +206,8 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, byte* end_p, siz memset(p + to_copy, 0, sz - to_copy); p += sz; } else { - while (sz--) { + // If we run out of args then we just finish; CPython would raise struct.error + while (sz-- && i < n_args) { mp_binary_set_val(fmt_type, *fmt, args[i++], &p); } } |