aboutsummaryrefslogtreecommitdiff
path: root/py/binary.c
diff options
context:
space:
mode:
authorBas van Sisseren <bas@vansisseren.nl>2017-08-12 14:40:49 +0200
committerDamien George <damien.p.george@gmail.com>2017-08-15 11:33:43 +1000
commita14ce77b28146526661c79c89b2e6ff6837c2bb0 (patch)
treea2ddf36cb50e584a59bcae8a36b9ab3bc7c0b535 /py/binary.c
parentc127ace28a4faeb93ef86743c703a14258137efc (diff)
py/binary.c: Fix bug when packing big-endian 'Q' values.
Without bugfix: struct.pack('>Q', 16) b'\x00\x00\x00\x10\x00\x00\x00\x00' With bugfix: struct.pack('>Q', 16) b'\x00\x00\x00\x00\x00\x00\x00\x10'
Diffstat (limited to 'py/binary.c')
-rw-r--r--py/binary.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/py/binary.c b/py/binary.c
index e38aae8ea..870a0942b 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -303,7 +303,10 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
// zero/sign extend if needed
if (BYTES_PER_WORD < 8 && size > sizeof(val)) {
int c = (is_signed(val_type) && (mp_int_t)val < 0) ? 0xff : 0x00;
- memset(p + sizeof(val), c, size - sizeof(val));
+ memset(p, c, size);
+ if (struct_type == '>') {
+ p += size - sizeof(val);
+ }
}
}
}