[cairo-commit] src/cairo-xlib-surface.c

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon Aug 28 19:30:40 PDT 2006


 src/cairo-xlib-surface.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

New commits:
diff-tree b6e5f2b0fef00352930dfcc47a13f330a13b1d68 (from 06a962886806be5e68061e24223c617980ac8248)
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Aug 28 22:30:38 2006 -0400

    [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;
        }

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 3965c21..55f95e8 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -2439,7 +2439,7 @@ _cairo_xlib_surface_add_glyph (Display *
 	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 *
 	    }
 	    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 *
 		n[0] = d[3];
 		d += 4;
 		n += 4;
+		c -= 4;
 	    }
 	    data = new;
 	}


More information about the cairo-commit mailing list