about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-06-04 15:29:38 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-06-04 15:29:38 +0000
commitc82d6a58d0cdd567916c732c45ae496ba03ec8be (patch)
tree8aa71df88d2cf5a6d74e7fe7aeb557f3e8bca84b /lib
parentbf7fe4a1d811fb8ddd2d9136c6b946954f3c5484 (diff)
downloadnetpbm-mirror-c82d6a58d0cdd567916c732c45ae496ba03ec8be.tar.gz
netpbm-mirror-c82d6a58d0cdd567916c732c45ae496ba03ec8be.tar.xz
netpbm-mirror-c82d6a58d0cdd567916c732c45ae496ba03ec8be.zip
merge pm_interpret_uint, pm_string_to_uint
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3262 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/libpm.c4
-rw-r--r--lib/util/nstring.c75
-rw-r--r--lib/util/nstring.h5
3 files changed, 25 insertions, 59 deletions
diff --git a/lib/libpm.c b/lib/libpm.c
index 783e9ed1..b335debb 100644
--- a/lib/libpm.c
+++ b/lib/libpm.c
@@ -848,7 +848,7 @@ pm_parse_width(const char * const arg) {
     unsigned int width;
     const char * error;
 
-    pm_interpret_uint(arg, &width, &error);
+    pm_string_to_uint(arg, &width, &error);
 
     if (error) {
         pm_error("'%s' is invalid as an image width.  %s", arg, error);
@@ -873,7 +873,7 @@ pm_parse_height(const char * const arg) {
     unsigned int height;
     const char * error;
 
-    pm_interpret_uint(arg, &height, &error);
+    pm_string_to_uint(arg, &height, &error);
 
     if (error) {
         pm_error("'%s' is invalid as an image height.  %s", arg, error);
diff --git a/lib/util/nstring.c b/lib/util/nstring.c
index 8cff4d56..7ef9fcfb 100644
--- a/lib/util/nstring.c
+++ b/lib/util/nstring.c
@@ -1007,43 +1007,6 @@ pm_strishex(const char * const subject) {
 
 
 void
-pm_interpret_uint(const char *   const string,
-                  unsigned int * const valueP,
-                  const char **  const errorP) {
-
-    if (string[0] == '\0')
-        pm_asprintf(errorP, "Null string.");
-    else {
-        /* strtoul() does a bizarre thing where if the number is out
-           of range, it returns a clamped value but tells you about it
-           by setting errno = ERANGE.  If it is not out of range,
-           strtoul() leaves errno alone.
-        */
-        char * tail;
-        unsigned long ulongValue;
-
-        errno = 0;  /* So we can tell if strtoul() overflowed */
-
-        ulongValue = strtoul(string, &tail, 10);
-
-        if (tail[0] != '\0')
-            pm_asprintf(errorP, "Non-digit stuff in string: %s", tail);
-        else if (errno == ERANGE)
-            pm_asprintf(errorP, "Number too large");
-        else if (ulongValue > UINT_MAX)
-            pm_asprintf(errorP, "Number too large");
-        else if (string[0] == '-')
-            pm_asprintf(errorP, "Negative number");
-            /* Sleazy code; string may have leading spaces. */
-        else {
-            *valueP = ulongValue;
-            *errorP = NULL;
-        }
-    }
-}
-
-
-void
 pm_string_to_uint(const char *   const string,
                   unsigned int * const uintP,
                   const char **  const errorP) {
@@ -1052,31 +1015,39 @@ pm_string_to_uint(const char *   const string,
         pm_asprintf(errorP, "Value is a null string");
     else {
         char * tailptr;
+        long longValue;
 
-        /* We can't use 'strtoull'.  Contrary to expectations, though as
+        /* We can't use 'strtoul'.  Contrary to expectations, though as
            designed, it returns junk if there is a minus sign.
         */
 
-        long longValue;
+        /* strtol() does a bizarre thing where if the number is out
+           of range, it returns a clamped value but tells you about it
+           by setting errno = ERANGE.  If it is not out of range,
+           strtol() leaves errno alone.
+        */
+        errno = 0;  /* So we can tell if strtoul() overflowed */
 
         longValue = strtol(string, &tailptr, 10);
 
-
-        *uintP = strtoul(string, &tailptr, 10);
-
         if (*tailptr != '\0')
             pm_asprintf(errorP, "Non-numeric crap in string: '%s'", tailptr);
         else {
-            if (longValue < 0)
-                pm_asprintf(errorP, "Number is negative");
-            else {
-                if ((unsigned int)longValue != longValue)
-                    pm_asprintf(errorP, "Number is too large for computation");
-                else {
-                    *uintP = (unsigned int)longValue;
-                    *errorP = NULL;
-                }
-            }
+             if (errno == ERANGE)
+                 pm_asprintf(errorP, "Number is too large for computation");
+             else {
+                 if (longValue < 0)
+                     pm_asprintf(errorP, "Number is negative");
+                 else {
+                     if ((unsigned int)longValue != longValue)
+                         pm_asprintf(errorP,
+                                     "Number is too large for computation");
+                     else {
+                         *uintP = (unsigned int)longValue;
+                         *errorP = NULL;
+                     }
+                 }
+             }
         }
     }
 }
diff --git a/lib/util/nstring.h b/lib/util/nstring.h
index 770700e0..5159277c 100644
--- a/lib/util/nstring.h
+++ b/lib/util/nstring.h
@@ -209,11 +209,6 @@ bool
 pm_strishex(const char * const subject);
 
 void
-pm_interpret_uint(const char *   const string,
-               unsigned int * const valueP,
-               const char **  const errorP);
-
-void
 pm_string_to_uint(const char *   const string,
                   unsigned int * const uintP,
                   const char **  const errorP);