diff options
author | Jeff Epler <jepler@gmail.com> | 2025-06-01 20:06:56 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-06-16 23:27:50 +1000 |
commit | 2c8ccd3ee8945d53857e383911bf822374174257 (patch) | |
tree | db185a186631b13dde43b6b08a997935155663ae /py/persistentcode.c | |
parent | 816246836e00b6c2af0ba26e8d16c234b43da4a0 (diff) |
py: Fix undefined left shift operations.
By ensuring the value to be shifted is an unsigned of the appropriate type.
This fixes several runtime diagnostics such as:
../../py/binary.c:199:28: runtime error:
left shift of 32768 by 16 places
cannot be represented in type 'int'
Signed-off-by: Jeff Epler <jepler@gmail.com>
Diffstat (limited to 'py/persistentcode.c')
-rw-r--r-- | py/persistentcode.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/py/persistentcode.c b/py/persistentcode.c index 43207a0cc..6ec0717f9 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -759,7 +759,7 @@ static void bit_vector_clear(bit_vector_t *self) { static bool bit_vector_is_set(bit_vector_t *self, size_t index) { const size_t bits_size = sizeof(*self->bits) * MP_BITS_PER_BYTE; return index / bits_size < self->alloc - && (self->bits[index / bits_size] & (1 << (index % bits_size))) != 0; + && (self->bits[index / bits_size] & ((uintptr_t)1 << (index % bits_size))) != 0; } static void bit_vector_set(bit_vector_t *self, size_t index) { @@ -770,7 +770,7 @@ static void bit_vector_set(bit_vector_t *self, size_t index) { self->bits = m_renew(uintptr_t, self->bits, self->alloc, new_alloc); self->alloc = new_alloc; } - self->bits[index / bits_size] |= 1 << (index % bits_size); + self->bits[index / bits_size] |= (uintptr_t)1 << (index % bits_size); } typedef struct _mp_opcode_t { |