about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/HISTORY2
-rw-r--r--generator/ppmpat.c3
2 files changed, 4 insertions, 1 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index b7ce7e00..16ae1d21 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -6,6 +6,8 @@ CHANGE HISTORY
 
 not yet  BJH  Release 10.82.00
 
+              ppmpat: Fix bug - crash or junk output with -camo or -anticamo
+              and no -color.  Introduced in Netpbm 10.78 (March 2017).
 
 17.12.30 BJH  Release 10.81.00
 
diff --git a/generator/ppmpat.c b/generator/ppmpat.c
index f1452fc7..908c200f 100644
--- a/generator/ppmpat.c
+++ b/generator/ppmpat.c
@@ -581,6 +581,7 @@ camoFill(pixel **         const pixels,
     pixel color;
 
     if (colorTableP->count > 0) {
+        assert(colorTableP->index < colorTableP->count);
         color = colorTableP->color[colorTableP->index];
         nextColorBg(colorTableP);
     } else if (antiflag)
@@ -650,7 +651,7 @@ camo(pixel **     const pixels,
 
     clearBackgroundCamo(pixels, cols, rows, maxval, colorTableP, antiflag);
 
-    if (colorTableP) {
+    if (colorTableP->count > 0) {
         assert(colorTableP->count > 1);
         colorTableP->index = 1;  /* Foreground colors start at 1 */
     }