about summary refs log tree commit diff
path: root/editor/pnmcat.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-12-09 18:23:34 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-12-09 18:23:34 +0000
commitaefcdcb26e6f076ece01d3af35e4a004ab105bff (patch)
tree07436bdbccefd7dbdaf7705b6e29d942d527a7a2 /editor/pnmcat.c
parente254440851e0631df7ef235027e0ce8c427c61e9 (diff)
downloadnetpbm-mirror-aefcdcb26e6f076ece01d3af35e4a004ab105bff.tar.gz
netpbm-mirror-aefcdcb26e6f076ece01d3af35e4a004ab105bff.tar.xz
netpbm-mirror-aefcdcb26e6f076ece01d3af35e4a004ab105bff.zip
fix arithmetic overflow
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@484 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor/pnmcat.c')
-rw-r--r--editor/pnmcat.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/editor/pnmcat.c b/editor/pnmcat.c
index 20dbf34d..cc86520f 100644
--- a/editor/pnmcat.c
+++ b/editor/pnmcat.c
@@ -155,7 +155,7 @@ computeOutputParms(unsigned int     const nfiles,
                    xelval *         const newmaxvalP,
                    int *            const newformatP) {
 
-    int newcols, newrows;
+    double newcols, newrows;
     int newformat;
     xelval newmaxval;
 
@@ -187,8 +187,18 @@ computeOutputParms(unsigned int     const nfiles,
             break;
 	    }
 	}
-    *newrowsP   = newrows;
-    *newcolsP   = newcols;
+
+    /* Note that while 'double' is not in general a precise numerical type,
+       in the case of a sum of integers which is less than INT_MAX, it
+       is exact, because double's precision is greater than int's.
+    */
+    if (newcols > INT_MAX)
+       pm_error("Output width too large: %.0f.", newcols);
+    if (newrows > INT_MAX)
+       pm_error("Output height too large: %.0f.", newrows);
+	
+    *newrowsP   = (int) newrows;
+    *newcolsP   = (int) newcols;
     *newmaxvalP = newmaxval;
     *newformatP = newformat;
 }