[PATCH 03/18] [RFC] mi: Avoid division by zero errors in miInitializeColormap()
Geert Uytterhoeven
geert at linux-m68k.org
Wed Mar 27 06:20:36 PDT 2013
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 <geert at linux-m68k.org>
---
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
More information about the xorg-devel
mailing list