mirror of
https://gitlab.freedesktop.org/xorg/lib/libxcursor.git
synced 2026-04-22 09:20:39 +02:00
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:
parent
bee68e54e5
commit
047993c76a
1 changed files with 3 additions and 2 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue