mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-04 21:04:18 +01:00
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 <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
c5d4c27a90
commit
63733c9133
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user