[xlib] Bug 7593: rewrite loop to be more readable, and fix warnings

Basically, it's evil to write a loop like:

    while ((c -= 4) > 0) {
        ...
    }

for one reason that doesn't work if c is unsigned.  And when c is signed, if
for some reason c is about -MAXINT, then it will overflow and not work as
expected.

It's much safer (and more gcc warning friendly) to rewrite it as:

    unsigned int c;

    while (c >= 4) {
        ...
        c -= 4;
    }
This commit is contained in:
Behdad Esfahbod 2006-08-28 22:30:38 -04:00
parent 06a9628868
commit b6e5f2b0fe

View file

@ -2439,7 +2439,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
break;
case CAIRO_FORMAT_ARGB32:
if (_native_byte_order_lsb() != (ImageByteOrder (dpy) == LSBFirst)) {
int c = glyph_surface->stride * glyph_surface->height;
unsigned int c = glyph_surface->stride * glyph_surface->height;
unsigned char *d;
unsigned char *new, *n;
@ -2450,7 +2450,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
}
n = new;
d = data;
while ((c -= 4) >= 0)
while (c >= 4)
{
n[3] = d[0];
n[2] = d[1];
@ -2458,6 +2458,7 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
n[0] = d[3];
d += 4;
n += 4;
c -= 4;
}
data = new;
}