addi style makemap could potentially read one past the end of an array
authorTony Cook <tony@develop-help.com>
Mon, 31 Dec 2018 11:02:27 +0000 (22:02 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 31 Dec 2018 11:02:27 +0000 (22:02 +1100)
Changes
quant.c

diff --git a/Changes b/Changes
index 0847cf8..82644d7 100644 (file)
--- a/Changes
+++ b/Changes
@@ -18,6 +18,9 @@ Coverity finally finished a build, fix a few problems:
  - initialize a pointer to prevent Coverity complaining in polygon
    drawing (it should always end up being set.)
 
+ - addi style makemap could potentially read one past the end of an
+   array.
+
 Imager 1.008 - 31 Dec 2018
 ============
 
diff --git a/quant.c b/quant.c
index e831abf..9d6e947 100644 (file)
--- a/quant.c
+++ b/quant.c
@@ -1514,7 +1514,7 @@ static void reorder(pbox prescan[512]) {
   c.cand++;
   c.pdc=c.pixcnt/(c.cand*c.cand); 
   /*  c.pdc=c.pixcnt/c.cand; */
-  while(c.pdc < prescan[nidx+1].pdc && nidx < 511) {
+  while(nidx < 511 && c.pdc < prescan[nidx+1].pdc) {
     prescan[nidx]=prescan[nidx+1];
     nidx++;
   }