diff options
author | Damien George <damien.p.george@gmail.com> | 2016-03-10 21:52:56 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-03-10 21:52:56 +0000 |
commit | 9ae51257bd40b1f010c2abbfb0a38b6d44860ea8 (patch) | |
tree | 11f120d0a18cfd186755be2b873803c4d10f58e2 /py/objint.c | |
parent | 5239a8a82b97db8c8e24d6087bed6cd72a5c3cb1 (diff) |
py: Use MP_SMALL_INT_POSITIVE_MASK to check if uint fits in a small int.
Using the original WORD_MSBIT_HIGH-logic resulted in errors when the
object model is not REPR_A or REPR_C.
Diffstat (limited to 'py/objint.c')
-rw-r--r-- | py/objint.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/py/objint.c b/py/objint.c index 46290a36f..9f948a145 100644 --- a/py/objint.c +++ b/py/objint.c @@ -311,9 +311,9 @@ mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) { } mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) { - // SMALL_INT accepts only signed numbers, of one bit less size - // then word size, which totals 2 bits less for unsigned numbers. - if ((value & (WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1))) == 0) { + // SMALL_INT accepts only signed numbers, so make sure the input + // value fits completely in the small-int positive range. + if ((value & ~MP_SMALL_INT_POSITIVE_MASK) == 0) { return MP_OBJ_NEW_SMALL_INT(value); } nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow")); |