about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--other/pnmcolormap.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/other/pnmcolormap.c b/other/pnmcolormap.c
index fbe85d4e..a1cb7a8c 100644
--- a/other/pnmcolormap.c
+++ b/other/pnmcolormap.c
@@ -731,7 +731,9 @@ splitBox(struct BoxVector *    const boxVectorP,
                          &oldBoxP->maxdim, &oldBoxP->spread);
     }
     {
-        struct Box * const newBoxP = &boxVectorP->box[boxVectorP->boxCt];
+        struct Box * const newBoxP = &boxVectorP->box[boxVectorP->boxCt++];
+
+        assert(boxVectorP->boxCt <= boxVectorP->capacity);
 
         newBoxP->startIndex = boxStart + medianIndex;
         newBoxP->colorCt    = boxSize - medianIndex;
@@ -739,7 +741,6 @@ splitBox(struct BoxVector *    const boxVectorP,
         computeBoxSpread(newBoxP, boxVectorP->colorFreqTable,
                          boxVectorP->colorDepth, methodForLargest,
                          &newBoxP->maxdim, &newBoxP->spread);
-        ++boxVectorP->boxCt;
     }
 
     sortBoxes(boxVectorP, methodForSplit);