mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-08 20:48:03 +02:00
[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:
parent
06a9628868
commit
b6e5f2b0fe
1 changed files with 3 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue