Skip to content

Commit

Permalink
py/binary: Do zero extension when storing a value larger than word size.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgeorge committed Dec 12, 2016
1 parent aee13ef commit a3c6100
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions py/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit a3c6100

Please sign in to comment.