From b6e5f2b0fef00352930dfcc47a13f330a13b1d68 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 28 Aug 2006 22:30:38 -0400 Subject: [PATCH] [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; } --- src/cairo-xlib-surface.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index 3965c2142..55f95e86a 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -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; }