[PATCH 4/4] winex11: Make color cubes as big as possible.

Alex Henrie alexhenrie24 at gmail.com
Thu Oct 29 22:30:22 CDT 2015


Cc: Patrik Stridvall <patrik at stridvall.se>
Cc: Greg Kreider <kreider at natlab.research.philips.com>
Cc: Vincent Povirk <vincent at codeweavers.com>

If palette_size - NB_RESERVED_COLORS is 1, 8, 27, 64, 125, or another
perfect cube, the green and blue sides of the cube were longer than the
red side and not all of the available memory was used. Also, if the
value was exactly 1, it would cause a division by zero error.

Coverity #713026, "divide_by_zero: In expression 192 / no_r, division
by expression no_r which may be zero has undefined behavior."

Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
 dlls/winex11.drv/palette.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/dlls/winex11.drv/palette.c b/dlls/winex11.drv/palette.c
index 953c9ea..f950334 100644
--- a/dlls/winex11.drv/palette.c
+++ b/dlls/winex11.drv/palette.c
@@ -594,10 +594,10 @@ static void X11DRV_PALETTE_FillDefaultColors( const PALETTEENTRY *sys_pal_templa
 
   if (palette_size <= NB_RESERVED_COLORS)
   	return;
-  while (i*i*i < (palette_size - NB_RESERVED_COLORS)) i++;
+  while (i*i*i <= (palette_size - NB_RESERVED_COLORS)) i++;
   no_r = no_g = no_b = --i;
-  if ((no_r * (no_g+1) * no_b) < (palette_size - NB_RESERVED_COLORS)) no_g++;
-  if ((no_r * no_g * (no_b+1)) < (palette_size - NB_RESERVED_COLORS)) no_b++;
+  if ((no_r * (no_g+1) * no_b) <= (palette_size - NB_RESERVED_COLORS)) no_g++;
+  if ((no_r * no_g * (no_b+1)) <= (palette_size - NB_RESERVED_COLORS)) no_b++;
   inc_r = (255 - NB_COLORCUBE_START_INDEX)/no_r;
   inc_g = (255 - NB_COLORCUBE_START_INDEX)/no_g;
   inc_b = (255 - NB_COLORCUBE_START_INDEX)/no_b;
-- 
2.6.2




More information about the wine-patches mailing list