Skip to content

Commit 9a99ff0

Browse files
committed
convert: avoid left shift into sign bit
Don't invoke undefined behavior due to integer promotion. Signed-off-by: Benjamin Gilbert <bgilbert@cs.cmu.edu>
1 parent 53faca7 commit 9a99ff0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎openslide/_convert.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ argb2rgba(PY_UINT32_T *buf, Py_ssize_t len)
4848
u8 g = 255 * ((val >> 8) & 0xff) / a;
4949
u8 b = 255 * ((val >> 0) & 0xff) / a;
5050
#ifdef WORDS_BIGENDIAN
51-
val = r << 24 | g << 16 | b << 8 | a;
51+
val = (PY_UINT32_T) r << 24 | g << 16 | b << 8 | a;
5252
#else
53-
val = a << 24 | b << 16 | g << 8 | r;
53+
val = (PY_UINT32_T) a << 24 | b << 16 | g << 8 | r;
5454
#endif
5555
buf[cur] = val;
5656
break;

0 commit comments

Comments
 (0)