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.
This commit is contained in:
Dave Reisner 2013-07-14 18:33:44 +02:00 committed by Daniel Stenberg
parent d3aaa68f55
commit f5005dd8d0
1 changed files with 7 additions and 3 deletions

View 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;
}
/*