From 1cd354d796aee73cc4334c2f17b1dc00c09d32a2 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 14 Jun 2014 19:33:59 +0200 Subject: [PATCH] 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 --- wrlib/convert.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wrlib/convert.c b/wrlib/convert.c index 95a14d45..6dfe2e41 100644 --- a/wrlib/convert.c +++ b/wrlib/convert.c @@ -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); } }