From 6fe0d63ef0343a68ff564e7ce58cd0d8d09c9c9a Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Tue, 27 Feb 2024 10:49:53 -0800 Subject: [PATCH 1/3] Fix shift-sign issue in Convert.c Fixes ``` libImaging/Convert.c:513:25: error: signed shift result (0xFF000000) sets the sign bit of the shift expression's type ('int') and becomes negative [-Werror,-Wshift-sign-overflow] UINT32 trns = (0xff << 24) | ((b & 0xff) << 16) | ((g & 0xff) << 8) | (r & 0xff); ~~~~ ^ ~~ ``` --- src/libImaging/Convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index 99d2a4ada70..acc1081545c 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -507,10 +507,10 @@ rgba2rgb_(UINT8 *out, const UINT8 *in, int xsize) { static void rgbT2rgba(UINT8 *out, int xsize, int r, int g, int b) { #ifdef WORDS_BIGENDIAN - UINT32 trns = ((r & 0xff) << 24) | ((g & 0xff) << 16) | ((b & 0xff) << 8) | 0xff; + UINT32 trns = ((r & 0xffU) << 24) | ((g & 0xffU) << 16) | ((b & 0xffU) << 8) | 0xffU; UINT32 repl = trns & 0xffffff00; #else - UINT32 trns = (0xff << 24) | ((b & 0xff) << 16) | ((g & 0xff) << 8) | (r & 0xff); + UINT32 trns = (0xffU << 24) | ((b & 0xffU) << 16) | ((g & 0xffU) << 8) | (r & 0xffU); UINT32 repl = trns & 0x00ffffff; #endif From 42620f1c19c0c3c7221429a2c0284d4d1cd4f9ec Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Sat, 9 Mar 2024 12:29:41 +1100 Subject: [PATCH 2/3] Leave unshifted int unchanged --- src/libImaging/Convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index acc1081545c..8ee5c091bcc 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -507,10 +507,10 @@ rgba2rgb_(UINT8 *out, const UINT8 *in, int xsize) { static void rgbT2rgba(UINT8 *out, int xsize, int r, int g, int b) { #ifdef WORDS_BIGENDIAN - UINT32 trns = ((r & 0xffU) << 24) | ((g & 0xffU) << 16) | ((b & 0xffU) << 8) | 0xffU; + UINT32 trns = ((r & 0xffU) << 24) | ((g & 0xffU) << 16) | ((b & 0xffU) << 8) | 0xff; UINT32 repl = trns & 0xffffff00; #else - UINT32 trns = (0xffU << 24) | ((b & 0xffU) << 16) | ((g & 0xffU) << 8) | (r & 0xffU); + UINT32 trns = (0xffU << 24) | ((b & 0xffU) << 16) | ((g & 0xffU) << 8) | (r & 0xff); UINT32 repl = trns & 0x00ffffff; #endif From 6432ec4bbcaed3e019648d4396f873b395b97755 Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Sat, 9 Mar 2024 15:54:55 +1100 Subject: [PATCH 3/3] Leave bitwise and operations unchanged --- src/libImaging/Convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index 8ee5c091bcc..59d18dd8838 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -507,10 +507,10 @@ rgba2rgb_(UINT8 *out, const UINT8 *in, int xsize) { static void rgbT2rgba(UINT8 *out, int xsize, int r, int g, int b) { #ifdef WORDS_BIGENDIAN - UINT32 trns = ((r & 0xffU) << 24) | ((g & 0xffU) << 16) | ((b & 0xffU) << 8) | 0xff; + UINT32 trns = ((r & 0xff) << 24) | ((g & 0xff) << 16) | ((b & 0xff) << 8) | 0xff; UINT32 repl = trns & 0xffffff00; #else - UINT32 trns = (0xffU << 24) | ((b & 0xffU) << 16) | ((g & 0xffU) << 8) | (r & 0xff); + UINT32 trns = (0xffU << 24) | ((b & 0xff) << 16) | ((g & 0xff) << 8) | (r & 0xff); UINT32 repl = trns & 0x00ffffff; #endif