about summary refs log tree commit diff
path: root/editor
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-08-13 15:30:10 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-08-13 15:30:10 +0000
commitb1830b8ae34b5d630accdd07f7db34624a826fd3 (patch)
treea55884a30ebc045879b62fc05819716b8310a2c9 /editor
parentf666f912c2822652a30baee490f3c2c3a9b92e75 (diff)
downloadnetpbm-mirror-b1830b8ae34b5d630accdd07f7db34624a826fd3.tar.gz
netpbm-mirror-b1830b8ae34b5d630accdd07f7db34624a826fd3.tar.xz
netpbm-mirror-b1830b8ae34b5d630accdd07f7db34624a826fd3.zip
Don't crash when cutting a region entirely to the left or right of the input image, with -pad
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@704 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor')
-rw-r--r--editor/pamcut.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/editor/pamcut.c b/editor/pamcut.c
index c6fc0cc1..f78f6622 100644
--- a/editor/pamcut.c
+++ b/editor/pamcut.c
@@ -400,13 +400,15 @@ struct rowCutter {
    create a new one then.
 */
 
+
+
 static void
 createRowCutter(struct pam *        const inpamP,
                 struct pam *        const outpamP,
                 int                 const leftcol,
                 int                 const rightcol,
                 struct rowCutter ** const rowCutterPP) {
-    
+
     struct rowCutter * rowCutterP;
     tuple * inputPointers;
     tuple * outputPointers;
@@ -414,7 +416,7 @@ createRowCutter(struct pam *        const inpamP,
     tuple blackTuple;
     tuple discardTuple;
     int col;
-    
+
     assert(inpamP->depth >= outpamP->depth);
         /* Entry condition.  If this weren't true, we could not simply
            treat an input tuple as an output tuple.
@@ -428,12 +430,12 @@ createRowCutter(struct pam *        const inpamP,
     MALLOCARRAY_NOFAIL(outputPointers, outpamP->width);
 
     /* Put in left padding */
-    for (col = leftcol; col < 0; ++col)
+    for (col = leftcol; col < 0 && col-leftcol < outpamP->width; ++col)
         outputPointers[col-leftcol] = blackTuple;
- 
+
     /* Put in extracted columns */
-    for (col = MAX(leftcol, 0); 
-         col <= MIN(rightcol, inpamP->width-1); 
+    for (col = MAX(leftcol, 0);
+         col <= MIN(rightcol, inpamP->width-1);
          ++col) {
         int const outcol = col - leftcol;
 
@@ -441,15 +443,18 @@ createRowCutter(struct pam *        const inpamP,
     }
 
     /* Put in right padding */
-    for (col = MIN(rightcol, inpamP->width-1) + 1; col <= rightcol; ++col)
-        outputPointers[col-leftcol] = blackTuple;
-    
+    for (col = MIN(rightcol, inpamP->width-1) + 1; col <= rightcol; ++col) {
+        if (col - leftcol >= 0) {
+            outputPointers[col-leftcol] = blackTuple;
+        }
+    }
+
     /* Direct input pixels that are getting cut off to the discard tuple */
 
-    for (col = 0; col < leftcol; ++col)
+    for (col = 0; col < MIN(leftcol, inpamP->width); ++col)
         inputPointers[col] = discardTuple;
 
-    for (col = rightcol + 1; col < inpamP->width; ++col)
+    for (col = MAX(0, rightcol + 1); col < inpamP->width; ++col)
         inputPointers[col] = discardTuple;
 
     MALLOCVAR_NOFAIL(rowCutterP);