diff --git a/extmod/crypto-algorithms/sha256.c b/extmod/crypto-algorithms/sha256.c index 24e964749b..ce0377208d 100644 --- a/extmod/crypto-algorithms/sha256.c +++ b/extmod/crypto-algorithms/sha256.c @@ -46,7 +46,7 @@ static void sha256_transform(CRYAL_SHA256_CTX *ctx, const BYTE data[]) WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64]; for (i = 0, j = 0; i < 16; ++i, j += 4) - m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]); + m[i] = ((uint32_t)data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]); for ( ; i < 64; ++i) m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16]; diff --git a/extmod/moduasyncio.c b/extmod/moduasyncio.c index 9717e38567..dd2d1e7475 100644 --- a/extmod/moduasyncio.c +++ b/extmod/moduasyncio.c @@ -31,6 +31,9 @@ #if MICROPY_PY_UASYNCIO +// Used when task cannot be guaranteed to be non-NULL. +#define TASK_PAIRHEAP(task) ((task) ? &(task)->pairheap : NULL) + #define TASK_STATE_RUNNING_NOT_WAITED_ON (mp_const_true) #define TASK_STATE_DONE_NOT_WAITED_ON (mp_const_none) #define TASK_STATE_DONE_WAS_WAITED_ON (mp_const_false) @@ -110,7 +113,7 @@ STATIC mp_obj_t task_queue_push_sorted(size_t n_args, const mp_obj_t *args) { assert(mp_obj_is_small_int(args[2])); task->ph_key = args[2]; } - self->heap = (mp_obj_task_t *)mp_pairheap_push(task_lt, &self->heap->pairheap, &task->pairheap); + self->heap = (mp_obj_task_t *)mp_pairheap_push(task_lt, TASK_PAIRHEAP(self->heap), TASK_PAIRHEAP(task)); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(task_queue_push_sorted_obj, 2, 3, task_queue_push_sorted); diff --git a/py/binary.c b/py/binary.c index 5c098b223d..05e658c952 100644 --- a/py/binary.c +++ b/py/binary.c @@ -202,7 +202,7 @@ long long mp_binary_get_int(size_t size, bool is_signed, bool big_endian, const delta = 1; } - long long val = 0; + unsigned long long val = 0; if (is_signed && *src & 0x80) { val = -1; } diff --git a/py/mpz.c b/py/mpz.c index e0d249c214..75e1fb1fdb 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -741,7 +741,7 @@ void mpz_set_from_ll(mpz_t *z, long long val, bool is_signed) { unsigned long long uval; if (is_signed && val < 0) { z->neg = 1; - uval = -val; + uval = -(unsigned long long)val; } else { z->neg = 0; uval = val; diff --git a/py/objint.c b/py/objint.c index 00375d388e..5ff5e7de4b 100644 --- a/py/objint.c +++ b/py/objint.c @@ -106,14 +106,14 @@ STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) { #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE e |= u.i[MP_ENDIANNESS_BIG] != 0; #endif - if ((e & ~(1 << MP_FLOAT_SIGN_SHIFT_I32)) == 0) { + if ((e & ~(1U << MP_FLOAT_SIGN_SHIFT_I32)) == 0) { // handle case of -0 (when sign is set but rest of bits are zero) e = 0; } else { - e += ((1 << MP_FLOAT_EXP_BITS) - 1) << MP_FLOAT_EXP_SHIFT_I32; + e += ((1U << MP_FLOAT_EXP_BITS) - 1) << MP_FLOAT_EXP_SHIFT_I32; } } else { - e &= ~((1 << MP_FLOAT_EXP_SHIFT_I32) - 1); + e &= ~((1U << MP_FLOAT_EXP_SHIFT_I32) - 1); } // 8 * sizeof(uintptr_t) counts the number of bits for a small int // TODO provide a way to configure this properly diff --git a/py/runtime.c b/py/runtime.c index cda26a9cf8..261670d4f3 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -392,7 +392,7 @@ mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { goto generic_binary_op; } else { // use standard precision - lhs_val <<= rhs_val; + lhs_val = (mp_uint_t)lhs_val << rhs_val; } break; } diff --git a/py/showbc.c b/py/showbc.c index 8941dd7544..cb81b88359 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -174,7 +174,7 @@ const byte *mp_bytecode_print_str(const mp_print_t *print, const byte *ip) { num--; } do { - num = (num << 7) | (*ip & 0x7f); + num = ((mp_uint_t)num << 7) | (*ip & 0x7f); } while ((*ip++ & 0x80) != 0); mp_printf(print, "LOAD_CONST_SMALL_INT " INT_FMT, num); break; diff --git a/py/smallint.h b/py/smallint.h index 58d843e8a1..67daf9b9fa 100644 --- a/py/smallint.h +++ b/py/smallint.h @@ -37,7 +37,7 @@ #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C #define MP_SMALL_INT_MIN ((mp_int_t)(((mp_int_t)MP_OBJ_WORD_MSBIT_HIGH) >> 1)) -#define MP_SMALL_INT_FITS(n) ((((n) ^ ((n) << 1)) & MP_OBJ_WORD_MSBIT_HIGH) == 0) +#define MP_SMALL_INT_FITS(n) ((((n) ^ ((mp_uint_t)(n) << 1)) & MP_OBJ_WORD_MSBIT_HIGH) == 0) // Mask to truncate mp_int_t to positive value #define MP_SMALL_INT_POSITIVE_MASK ~(MP_OBJ_WORD_MSBIT_HIGH | (MP_OBJ_WORD_MSBIT_HIGH >> 1)) diff --git a/py/vm.c b/py/vm.c index f9a589c9d1..5365014fcb 100644 --- a/py/vm.c +++ b/py/vm.c @@ -312,7 +312,7 @@ dispatch_loop: DISPATCH(); ENTRY(MP_BC_LOAD_CONST_SMALL_INT): { - mp_int_t num = 0; + mp_uint_t num = 0; if ((ip[0] & 0x40) != 0) { // Number is negative num--;