From: Dave Reisner Date: Sun, 14 Jul 2013 16:33:44 +0000 (+0200) Subject: src/tool_paramhlp: try harder to catch negatives X-Git-Tag: curl-7_32_0~103 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f5005dd8d0afc6a2774e43f5688fecc6a192b38a;p=thirdparty%2Fcurl.git src/tool_paramhlp: try harder to catch negatives 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. --- diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 97540d11be..d232450462 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -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; } /*