aboutsummaryrefslogtreecommitdiff
path: root/py/binary.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-04-25 23:51:14 +0100
committerDamien George <damien.p.george@gmail.com>2015-04-25 23:51:14 +0100
commit9472907ae1906ccff7ce5cab24f0fa9d146c4534 (patch)
tree68f5c29f761b7318f5f21f7bb82cbd305e92bce4 /py/binary.c
parentae2c81ff388d9b06bc11ac1e14bd5d71b4f4637c (diff)
py: Fix handling of negative numbers in struct.pack of q/Q.
Diffstat (limited to 'py/binary.c')
-rw-r--r--py/binary.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/py/binary.c b/py/binary.c
index 8b5c05ab3..ee00c4e34 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -291,6 +291,10 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
#endif
{
val = mp_obj_get_int(val_in);
+ // sign extend if needed
+ if (BYTES_PER_WORD < 8 && size > sizeof(val) && is_signed(val_type) && (mp_int_t)val < 0) {
+ memset(p + sizeof(val), 0xff, size - sizeof(val));
+ }
}
}