curl-library
[PATCH 1/3] src/tool_paramhlp: try harder to catch negatives
From: Dave Reisner <dreisner_at_archlinux.org>
Date: Sun, 14 Jul 2013 12:33:44 -0400
Date: Sun, 14 Jul 2013 12:33:44 -0400
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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 97540d1..d232450 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; } /* -- 1.8.3.2 ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.htmlReceived on 2013-07-14