about summary refs log tree commit diff
path: root/generator
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-03-12 15:26:17 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2020-03-12 15:26:17 +0000
commit5138724173ccb103d7b02427c87317d4bc11b5b7 (patch)
treefb205f06b6bcda8f6d144af48b2985ce57f1cbeb /generator
parentb385637b4b66e511db8262915a247069852e47a5 (diff)
downloadnetpbm-mirror-5138724173ccb103d7b02427c87317d4bc11b5b7.tar.gz
netpbm-mirror-5138724173ccb103d7b02427c87317d4bc11b5b7.tar.xz
netpbm-mirror-5138724173ccb103d7b02427c87317d4bc11b5b7.zip
Fix error messages for invalid height, width arguments
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3744 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator')
-rw-r--r--generator/pgmnoise.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/generator/pgmnoise.c b/generator/pgmnoise.c
index f76009b2..e3e4eca6 100644
--- a/generator/pgmnoise.c
+++ b/generator/pgmnoise.c
@@ -3,11 +3,12 @@
    Frank Neumann, October 1993
 *********************************************************************/
 
+#include <assert.h>
 #include "pm_c_util.h"
 #include "mallocvar.h"
+#include "nstring.h"
 #include "shhopt.h"
 #include "pgm.h"
-#include <assert.h>
 
 
 
@@ -68,16 +69,24 @@ parseCommandLine(int argc, const char ** const argv,
                  "Arguments are width and height of image, in pixels",
                  argc-1);
     else {
-        int const width  = atoi(argv[1]);
-        int const height = atoi(argv[2]);
-
-        if (width <= 0)
-            pm_error("Width must be positive, not %d", width);
+        const char * error; /* error message of pm_string_to_uint */
+        unsigned int width, height;
+
+        pm_string_to_uint(argv[1], &width, &error);
+        if (error)
+            pm_error("Width argument is not an unsigned integer.  %s",
+                     error);
+        else if (width == 0)
+            pm_error("Width argument is zero; must be positive");
         else
             cmdlineP->width = width;
 
-        if (height <= 0)
-            pm_error("Height must be positive, not %d", width);
+        pm_string_to_uint(argv[2], &height, &error);
+        if (error)
+            pm_error("Height argument is not an unsigned integer.  %s ",
+                     error);
+        else if (height == 0)
+            pm_error("Height argument is zero; must be positive");
         else
             cmdlineP->height = height;
     }