From 5138724173ccb103d7b02427c87317d4bc11b5b7 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Thu, 12 Mar 2020 15:26:17 +0000 Subject: 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 --- generator/pgmnoise.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'generator') 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 #include "pm_c_util.h" #include "mallocvar.h" +#include "nstring.h" #include "shhopt.h" #include "pgm.h" -#include @@ -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; } -- cgit 1.4.1