diff --git a/dix/colormap.c b/dix/colormap.c index 6ae8b1649..bde8a8b1e 100644 --- a/dix/colormap.c +++ b/dix/colormap.c @@ -1295,7 +1295,7 @@ FindColorInRootCmap(ColormapPtr pmap, EntryPtr pentFirst, int size, if ((pixel = *pPixel) >= size) pixel = 0; - for (pent = pentFirst + pixel, count = size; --count >= 0; pent++, pixel++) { + for (pent = pentFirst + pixel, count = size; --count >= 0;) { if (pent->refcnt > 0 && (*comp) (pent, prgb)) { switch (channel) { case REDMAP: @@ -1312,6 +1312,13 @@ FindColorInRootCmap(ColormapPtr pmap, EntryPtr pentFirst, int size, } *pPixel = pixel; } + pixel++; + if (pixel >= size) { + pent = pentFirst; + pixel = 0; + } + else + pent++; } }