conf.c: parsing floating point numbers
PATCH 1/1 conf.c: parsing floating point numbers
When parse_value finds something looking like a number, it first calls safe_strtoll to test whether the value's type is integer. Unfortunately, safe_strtoll simply grabs anything which may be an integer, and doesn't check for any following characters (e.g. the decimal point of a floating point number).
This means that all floating point numbers are parsed as integers.
The patch adds a check for the end of the string, similar to safe_strtol and safe_strtod.
src/conf.c Tue Jul 2 00:52:22 2002 renamed from src/conf.c.org Tue Jul 2 00:39:34 2002 +4 -1
@@ -463,11 +463,14 @@ int safe_strtoll(const char *str, long long *val) { long long v; + int endidx; if (!*str) return -EINVAL; errno = 0; - if (sscanf(str, "%Ld", &v) != 1) + if (sscanf(str, "%Ld%n", &v, &endidx) < 1) return -EINVAL; + if (str[endidx]) + return -EINVAL; *val = v; return 0; }
Clemens
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Takashi Iwai
AppliedAt Tue, 02 Jul 2002 10:52:03 +0200,
Quoted 11 lines · Clemens Ladisch
When
parse_valuefinds something looking like a number, it first callssafe_strtollto test whether the value's type is integer. Unfortunately,safe_strtollsimply grabs anything which may be an integer, and doesn't check for any following characters (e.g. the decimal point of a floating point number).This means that all floating point numbers are parsed as integers.
The patch adds a check for the end of the string, similar to
safe_strtolandsafe_strtod.
thanks, applied to cvs.
Takashi
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
No, I will not fix your computer.
http://thinkgeek.com/sf