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).
diff --git a/py/modstruct.c b/py/modstruct.c
index 1daa333..0d4a45f 100644
--- a/py/modstruct.c
+++ b/py/modstruct.c
@@ -206,7 +206,8 @@
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);
}
}