diff options
author | Bert Pauline <bert.pauline@fake-box.com> | 2018-04-28 10:22:00 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2018-04-29 17:43:38 +0100 |
commit | 979a87b9bcf40d583251f6e450a7afd8f07d1fe1 (patch) | |
tree | 862a4dbabbb7016fa559e81feb1d976294386b17 | |
parent | 87f8f4bf01dfb9982c1ef991e4060a5e19fdb7a7 (diff) | |
download | gdk-pixbuf-979a87b9bcf40d583251f6e450a7afd8f07d1fe1.tar.gz |
gdk-pixbuf-xlib: Fix out-of-bounds error in dithering loop
Use two loops to traverse the array of arrays `DM`, i.e. use `DM[y][x]`
instead of `DM[0][i]`.
This resolves a warning about undefined behavior when compiling with GCC
with aggressive loop optimizations enabled.
While we are at it: Move the variable definitions into the body of the
outer if-statement.
https://bugzilla.gnome.org/show_bug.cgi?id=748211
-rw-r--r-- | contrib/gdk-pixbuf-xlib/gdk-pixbuf-xlibrgb.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/contrib/gdk-pixbuf-xlib/gdk-pixbuf-xlibrgb.c b/contrib/gdk-pixbuf-xlib/gdk-pixbuf-xlibrgb.c index a87158688..dfde1aeaf 100644 --- a/contrib/gdk-pixbuf-xlib/gdk-pixbuf-xlibrgb.c +++ b/contrib/gdk-pixbuf-xlib/gdk-pixbuf-xlibrgb.c @@ -1346,19 +1346,24 @@ static guint32 *DM_565 = NULL; static void xlib_rgb_preprocess_dm_565 (void) { - int i; - guint32 dith; - if (DM_565 == NULL) { + int i, x, y; + guint32 dith; + DM_565 = malloc(sizeof(guint32) * DM_WIDTH * DM_HEIGHT); - for (i = 0; i < DM_WIDTH * DM_HEIGHT; i++) + i = 0; + for (y = 0; y < DM_HEIGHT; y++) { - dith = DM[0][i] >> 3; - DM_565[i] = (dith << 20) | dith | (((7 - dith) >> 1) << 10); + for (x = 0; x < DM_WIDTH; x++) + { + dith = DM[y][x] >> 3; + DM_565[i] = (dith << 20) | dith | (((7 - dith) >> 1) << 10); #ifdef VERBOSE - printf ("%i %x %x\n", i, dith, DM_565[i]); + printf ("%i %x %x\n", i, dith, DM_565[i]); #endif + i++; + } } } } |