about summary refs log tree commit diff
path: root/generator
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2021-08-12 01:37:43 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2021-08-12 01:37:43 +0000
commit1ceadd9f21d6ebadb2b40247f19f11f1b6493dc4 (patch)
tree0adce1ca90a1b004f5c5a8c8a9f043432f31a6d6 /generator
parentaff5c0073a5f6f296c5dc7d9f57ca090a7348879 (diff)
downloadnetpbm-mirror-1ceadd9f21d6ebadb2b40247f19f11f1b6493dc4.tar.gz
netpbm-mirror-1ceadd9f21d6ebadb2b40247f19f11f1b6493dc4.tar.xz
netpbm-mirror-1ceadd9f21d6ebadb2b40247f19f11f1b6493dc4.zip
Fix crash with -xbegin=0
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4125 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator')
-rw-r--r--generator/pamstereogram.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/generator/pamstereogram.c b/generator/pamstereogram.c
index 6e64b127..4bc1ea92 100644
--- a/generator/pamstereogram.c
+++ b/generator/pamstereogram.c
@@ -1220,15 +1220,19 @@ makeImageRow(outGenerator *       const outGenP,
     unsigned int const height = outGenP->pam.height;
 
     unsigned int col;
-    int lastLinked;
+    bool colHasBeenLinked;
+    unsigned int lastLinkedCol;
+        /* Last column to have been linked; meaningless if 'colHasBeenLinked'
+           is false.
+        */
 
-    for (col = xbegin, lastLinked = -1; col < width; ++col) {
+    for (col = xbegin, colHasBeenLinked = false; col < width; ++col) {
 
         tuple newtuple;
 
         if (sameL[col] == col || sameL[col] < xbegin) {
-            if (lastLinked == col - 1)
-                newtuple = outRow[col - 1];
+            if (colHasBeenLinked && lastLinkedCol == col - 1)
+                newtuple = outRow[lastLinkedCol];
             else {
                 if (col < xbegin + farWidth)
                     newtuple = outGenP->getTuple(outGenP, col, row);
@@ -1237,19 +1241,20 @@ makeImageRow(outGenerator *       const outGenP,
                         outGenP, col, (row + height - yfillshift) % height);
             }
         } else {
-          newtuple = outRow[sameL[col]];
-          lastLinked = col;
-              /* Keep track of the last pixel to be constrained. */
+            newtuple = outRow[sameL[col]];
+            colHasBeenLinked = true;
+            lastLinkedCol = col;
+                /* Keep track of the last pixel to be constrained. */
         }
         pnm_assigntuple(&outGenP->pam, outRow[col], newtuple);
     }
 
-    for (col = xbegin, lastLinked = -1; col > 0; --col) {
+    for (col = xbegin, colHasBeenLinked = false; col > 0; --col) {
         tuple newtuple;
 
         if (sameR[col-1] == col-1) {
-            if (lastLinked == col)
-                newtuple = outRow[col];
+            if (colHasBeenLinked && lastLinkedCol == col)
+                newtuple = outRow[lastLinkedCol];
             else {
                 if (col > xbegin - farWidth)
                     newtuple = outGenP->getTuple(outGenP, col-1, row);
@@ -1259,7 +1264,8 @@ makeImageRow(outGenerator *       const outGenP,
             }
         } else {
             newtuple = outRow[sameR[col-1]];
-            lastLinked = col-1;
+            colHasBeenLinked = true;
+            lastLinkedCol = col - 1;
                 /* Keep track of the last pixel to be constrained. */
         }
         pnm_assigntuple(&outGenP->pam, outRow[col-1], newtuple);