From 63733c913316861582f2330c13741ef3862d4d87 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 29 Nov 2014 16:35:18 +0100 Subject: [PATCH] WINGs: fix possible problems due to sign extension when setting Icon (Coverity #50202) As pointed by Coverity, there might be some problems due to sign extension when performing the shifts and ors operations when converting the RImage to the format expected for the WM_ICON property. This patch try to improve things by using as much as possible unsigned types and by using explicit types conversion instead of counting on the wrong implicit type conversion done by the language. Signed-off-by: Christophe CURIS --- WINGs/wwindow.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/WINGs/wwindow.c b/WINGs/wwindow.c index a04ab6ae..28844fb9 100644 --- a/WINGs/wwindow.c +++ b/WINGs/wwindow.c @@ -217,7 +217,7 @@ static void setMiniwindowTitle(WMWindow * win, const char *title) static void setMiniwindow(WMWindow *win, RImage *image) { WMScreen *scr = win->view->screen; - long *data; + unsigned long *data; int x, y; int o; @@ -232,15 +232,19 @@ static void setMiniwindow(WMWindow *win, RImage *image) for (y = 0; y < image->height; y++) { for (x = 0; x < image->width; x++) { - long pixel; + unsigned long pixel; int offs = (x + y * image->width); - if (image->format == RRGBFormat) - pixel = image->data[offs * 3] << 16 | image->data[offs * 3 + 1] << 8 - | image->data[offs * 3 + 2]; - else - pixel = image->data[offs * 4] << 16 | image->data[offs * 4 + 1] << 8 - | image->data[offs * 4 + 2] | image->data[offs * 4 + 3] << 24; + if (image->format == RRGBFormat) { + pixel = ((unsigned long) image->data[offs * 3 ]) << 16; + pixel |= ((unsigned long) image->data[offs * 3 + 1]) << 8; + pixel |= ((unsigned long) image->data[offs * 3 + 2]); + } else { + pixel = ((unsigned long) image->data[offs * 4 ]) << 16; + pixel |= ((unsigned long) image->data[offs * 4 + 1]) << 8; + pixel |= ((unsigned long) image->data[offs * 4 + 2]); + pixel |= ((unsigned long) image->data[offs * 4 + 3]) << 24; + } data[o++] = pixel; }