Commit 979a87b9 authored by Bert Pauline's avatar Bert Pauline Committed by Emmanuele Bassi

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
parent 87f8f4bf
......@@ -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++;
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment