]> granicus.if.org Git - curl/commitdiff
src/tool_paramhlp: try harder to catch negatives
authorDave Reisner <dreisner@archlinux.org>
Sun, 14 Jul 2013 16:33:44 +0000 (18:33 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 14 Jul 2013 20:48:29 +0000 (22:48 +0200)
strto* functions happily chomp off leading whitespace, so simply
checking for str[0] can lead to false negatives. Do the full parse and
check the out value instead.

src/tool_paramhlp.c

index 97540d11bee4a0fa62bc19948eff44be0963d248..d2324504628645c5f72577f88eb2143525a70b04 100644 (file)
@@ -178,9 +178,13 @@ ParameterError str2num(long *val, const char *str)
 
 ParameterError str2unum(long *val, const char *str)
 {
-  if(str[0]=='-')
-    return PARAM_NEGATIVE_NUMERIC; /* badness */
-  return str2num(val, str);
+  ParameterError result = str2num(val, str);
+  if(result != PARAM_OK)
+    return result;
+  if(*val < 0)
+    return PARAM_NEGATIVE_NUMERIC;
+
+  return PARAM_OK;
 }
 
 /*