Skip to content

Commit a3c6100

Browse files
committed
py/binary: Do zero extension when storing a value larger than word size.
1 parent aee13ef commit a3c6100

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

py/binary.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,10 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
294294
#endif
295295
{
296296
val = mp_obj_get_int(val_in);
297-
// sign extend if needed
298-
if (BYTES_PER_WORD < 8 && size > sizeof(val) && is_signed(val_type) && (mp_int_t)val < 0) {
299-
memset(p + sizeof(val), 0xff, size - sizeof(val));
297+
// zero/sign extend if needed
298+
if (BYTES_PER_WORD < 8 && size > sizeof(val)) {
299+
int c = (is_signed(val_type) && (mp_int_t)val < 0) ? 0xff : 0x00;
300+
memset(p + sizeof(val), c, size - sizeof(val));
300301
}
301302
}
302303
}

0 commit comments

Comments
 (0)