[gdk-pixbuf] gdk-pixbuf-xlib: Fix out-of-bounds error in dithering loop



commit 979a87b9bcf40d583251f6e450a7afd8f07d1fe1
Author: Bert Pauline <bert pauline fake-box com>
Date:   Sat Apr 28 10:22:00 2018 +0000

    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

 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 a871586..dfde1ae 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++;
+           }
        }
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]