Correct error handling in _XcursorAverageColor

Previously it would either div-zero or get stuck in a loop until int overflow
if called with a bad value.

cursor.c:214:32: warning: Division by zero
    return (0xff << 24) | ((red/npixels) << 16) | ((green/npixels) << 8) | (blue/npixels);

Found-by: clang static analyzer
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
This commit is contained in:
Jeremy Huddleston 2011-05-07 10:16:18 -07:00
parent bee68e54e5
commit 047993c76a

View file

@ -201,6 +201,9 @@ _XcursorAverageColor (XcursorPixel *pixels, int npixels)
XcursorPixel red, green, blue;
int n = npixels;
if (n < 1)
return 0;
blue = green = red = 0;
while (n--)
{
@ -209,8 +212,6 @@ _XcursorAverageColor (XcursorPixel *pixels, int npixels)
green += (p >> 8) & 0xff;
blue += (p >> 0) & 0xff;
}
if (!n)
return 0;
return (0xff << 24) | ((red/npixels) << 16) | ((green/npixels) << 8) | (blue/npixels);
}