diff options
author | Dave Reisner <dreisner@archlinux.org> | 2013-07-14 18:33:44 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2013-07-14 22:48:29 +0200 |
commit | f5005dd8d0afc6a2774e43f5688fecc6a192b38a (patch) | |
tree | 73cd1dca771ffbaa7ef9c717eb6b2f2aaaa5c2fa /src | |
parent | d3aaa68f55137bfa6443ddfbb6d084d5f8084f97 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/tool_paramhlp.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 97540d11b..d23245046 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; } /* |