File tree Expand file tree Collapse file tree 3 files changed +9
-9
lines changed
Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -311,9 +311,9 @@ mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
311311}
312312
313313mp_obj_t mp_obj_new_int_from_uint (mp_uint_t value ) {
314- // SMALL_INT accepts only signed numbers, of one bit less size
315- // then word size, which totals 2 bits less for unsigned numbers .
316- if ((value & ( WORD_MSBIT_HIGH | ( WORD_MSBIT_HIGH >> 1 )) ) == 0 ) {
314+ // SMALL_INT accepts only signed numbers, so make sure the input
315+ // value fits completely in the small-int positive range .
316+ if ((value & ~ MP_SMALL_INT_POSITIVE_MASK ) == 0 ) {
317317 return MP_OBJ_NEW_SMALL_INT (value );
318318 }
319319 nlr_raise (mp_obj_new_exception_msg (& mp_type_OverflowError , "small int overflow" ));
Original file line number Diff line number Diff line change @@ -223,9 +223,9 @@ mp_obj_t mp_obj_new_int(mp_int_t value) {
223223}
224224
225225mp_obj_t mp_obj_new_int_from_uint (mp_uint_t value ) {
226- // SMALL_INT accepts only signed numbers, of one bit less size
227- // than word size, which totals 2 bits less for unsigned numbers .
228- if ((value & ( WORD_MSBIT_HIGH | ( WORD_MSBIT_HIGH >> 1 )) ) == 0 ) {
226+ // SMALL_INT accepts only signed numbers, so make sure the input
227+ // value fits completely in the small-int positive range .
228+ if ((value & ~ MP_SMALL_INT_POSITIVE_MASK ) == 0 ) {
229229 return MP_OBJ_NEW_SMALL_INT (value );
230230 }
231231 return mp_obj_new_int_from_ll (value );
Original file line number Diff line number Diff line change @@ -357,9 +357,9 @@ mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
357357}
358358
359359mp_obj_t mp_obj_new_int_from_uint (mp_uint_t value ) {
360- // SMALL_INT accepts only signed numbers, of one bit less size
361- // than word size, which totals 2 bits less for unsigned numbers .
362- if ((value & ( WORD_MSBIT_HIGH | ( WORD_MSBIT_HIGH >> 1 )) ) == 0 ) {
360+ // SMALL_INT accepts only signed numbers, so make sure the input
361+ // value fits completely in the small-int positive range .
362+ if ((value & ~ MP_SMALL_INT_POSITIVE_MASK ) == 0 ) {
363363 return MP_OBJ_NEW_SMALL_INT (value );
364364 }
365365 return mp_obj_new_int_from_ull (value );
You can’t perform that action at this time.
0 commit comments