Skip to content

Commit 2bddfd4

Browse files
committed
py/obj.h: When constructing a small-int cast to mp_uint_t for bit-shift.
The C standard says that left-shifting a signed value (on the LHS of the operator) is undefined. So we cast to an unsigned integer before the shift. gcc does not issue a warning about this, but clang does.
1 parent 237c519 commit 2bddfd4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

py/obj.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
8383
static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o)
8484
{ return ((((mp_int_t)(o)) & 1) != 0); }
8585
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
86-
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_int_t)(small_int)) << 1) | 1))
86+
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
8787

8888
static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
8989
{ return ((((mp_int_t)(o)) & 3) == 2); }
@@ -109,7 +109,7 @@ static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o)
109109
static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o)
110110
{ return ((((mp_int_t)(o)) & 3) == 1); }
111111
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 2)
112-
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_int_t)(small_int)) << 2) | 1))
112+
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 2) | 1))
113113

114114
static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
115115
{ return ((((mp_int_t)(o)) & 3) == 3); }
@@ -135,7 +135,7 @@ static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o)
135135
static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o)
136136
{ return ((((mp_int_t)(o)) & 1) != 0); }
137137
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
138-
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_int_t)(small_int)) << 1) | 1))
138+
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
139139

140140
#define mp_const_float_e MP_ROM_PTR((mp_obj_t)(((0x402df854 & ~3) | 2) + 0x80800000))
141141
#define mp_const_float_pi MP_ROM_PTR((mp_obj_t)(((0x40490fdb & ~3) | 2) + 0x80800000))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy