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 <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS authored and Carlos R. Mafra committed 2014-06-15 19:45:20 +01:00
1 parent 1cd354d796
commit 6505b2f81c
1 file changed
+3 -2
+3 -2
View File
@@ -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;