From 6505b2f81c8b7ea004dd0f24167f5ce3c9b641f3 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 14 Jun 2014 19:34:00 +0200 Subject: [PATCH] wrlib: fix possible incorrect shifting operations (Coverity #50204, #50205, #50206) 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wrlib/convert.c b/wrlib/convert.c index 6dfe2e41..b0ab2303 100644 --- a/wrlib/convert.c +++ b/wrlib/convert.c @@ -978,8 +978,9 @@ Bool RGetClosestXColor(RContext * context, const RColor * color, XColor * retCol gtable = computeTable(gmask); btable = computeTable(bmask); - retColor->pixel = (rtable[color->red] << roffs) | - (gtable[color->green] << goffs) | (btable[color->blue] << boffs); + retColor->pixel = (((unsigned long) rtable[color->red]) << roffs) + | (((unsigned long) gtable[color->green]) << goffs) + | (((unsigned long) btable[color->blue]) << boffs); retColor->red = color->red << 8; retColor->green = color->green << 8;