summaryrefslogtreecommitdiffstatshomepage
path: root/py/binary.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-12-12 15:00:06 +1100
committerDamien George <damien.p.george@gmail.com>2016-12-12 15:00:06 +1100
commita3c61004c2139091b24c81e22fa5afa9fa5f4979 (patch)
tree6b225bbeaf21e2bc1dd88626681b5b24e78ce3ad /py/binary.c
parentaee13ef3f219a7a2e19c017323694b946d500d14 (diff)
downloadmicropython-a3c61004c2139091b24c81e22fa5afa9fa5f4979.tar.gz
micropython-a3c61004c2139091b24c81e22fa5afa9fa5f4979.zip
py/binary: Do zero extension when storing a value larger than word size.
Diffstat (limited to 'py/binary.c')
-rw-r--r--py/binary.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/py/binary.c b/py/binary.c
index 699324bc6e..d22e0f342d 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -294,9 +294,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));
+ // 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));
}
}
}