Re: [PATCH 03/18] [RFC] mi: Avoid division by zero errors in miInitializeColormap()

2013-04-08 Thread Keith Packard
Geert Uytterhoeven  writes:

> Question: Should we restrict depth < 3 to grayscale visuals instead?
> For monochrome this is already needed, as miCreateDefColormap() only
> preallocates black and white pixels if depth > 1.

Yes, it doesn't make sense to offer static color and true color for this
hardware. I'd suggest that miInitializeColormap should probably return
failure when trying to initialize a TrueColor or StaticColor colormap
where you're getting a color plane or line instead of a color cube :-)

-- 
keith.pack...@intel.com


pgpDkCelvy3Pl.pgp
Description: PGP signature


[PATCH 03/18] [RFC] mi: Avoid division by zero errors in miInitializeColormap()

2013-03-27 Thread Geert Uytterhoeven
If depth < 3, one or more of {red,green,blue}Mask and lim[rgb] will be
zero, causing division by zero errors. Add checks to avoid this.

Question: Should we restrict depth < 3 to grayscale visuals instead?
For monochrome this is already needed, as miCreateDefColormap() only
preallocates black and white pixels if depth > 1.

Signed-off-by: Geert Uytterhoeven 
---
 mi/micmap.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mi/micmap.c b/mi/micmap.c
index 3ef0c8c..c02596b 100644
--- a/mi/micmap.c
+++ b/mi/micmap.c
@@ -138,13 +138,13 @@ miInitializeColormap(ColormapPtr pmap)
 limb = pVisual->blueMask >> pVisual->offsetBlue;
 for (i = 0; i <= maxent; i++) {
 /* rescale to [0..65535] then rgb bits */
-pmap->red[i].co.local.red =
+pmap->red[i].co.local.red = !limr ? 0 :
 ((i & pVisual->redMask) >> pVisual->offsetRed)
 * 65535) / limr) >> shift) * 65535) / lim;
-pmap->red[i].co.local.green =
+pmap->red[i].co.local.green = !limg ? 0 :
 ((i & pVisual->greenMask) >> pVisual->offsetGreen)
 * 65535) / limg) >> shift) * 65535) / lim;
-pmap->red[i].co.local.blue =
+pmap->red[i].co.local.blue = !limb ? 0 :
 ((i & pVisual->blueMask) >> pVisual->offsetBlue)
 * 65535) / limb) >> shift) * 65535) / lim;
 }
-- 
1.7.0.4


-- 
To UNSUBSCRIBE, email to debian-x-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/1364390451-9656-4-git-send-email-ge...@linux-m68k.org