1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-24 07:02:30 +01:00

wrlib: fix possible incorrect shifting operations (Coverity #50203)

As pointed by Coverity, the shift operation performed for color-to-pixel
transform may not behave as well as expected because of the types used
(Coverity pointing suspicious sign extension because of int type being
involved).

The new code tries to leave no open interpretation to the compiler.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2014-06-14 19:33:59 +02:00
committed by Carlos R. Mafra
parent 5f1e25152c
commit 1cd354d796

View File

@@ -326,7 +326,8 @@ static RXImage *image2TrueColor(RContext * ctx, RImage * image)
}
if (ctx->attribs->render_mode == RBestMatchRendering) {
int ofs, r, g, b;
int ofs;
unsigned long r, g, b;
int x, y;
unsigned long pixel;
unsigned char *ptr = image->data;
@@ -339,7 +340,10 @@ static RXImage *image2TrueColor(RContext * ctx, RImage * image)
for (y = 0; y < image->height; y++) {
for (x = 0; x < image->width; x++, ptr += channels) {
/* reduce pixel */
pixel = (*(ptr) << roffs) | (*(ptr + 1) << goffs) | (*(ptr + 2) << boffs);
r = ptr[0];
g = ptr[1];
b = ptr[2];
pixel = (r << roffs) | (g << goffs) | (b << boffs);
XPutPixel(ximg->image, x, y, pixel);
}
}