From bc9d16b79f4e8c25e13be63f846cfd7152b65da1 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Mon, 22 Jun 2015 02:12:32 +0100 Subject: numfmt: handle leading zeros correctly * src/numfmt.c (simple_strtod_int): Don't count leading zeros as significant digits. Also have leading zeros as optional for floating point numbers. * tests/misc/numfmt.pl: Add test cases. * NEWS: Mention the fix. --- src/numfmt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/numfmt.c') diff --git a/src/numfmt.c b/src/numfmt.c index 82a958549..1a7185f2b 100644 --- a/src/numfmt.c +++ b/src/numfmt.c @@ -462,6 +462,7 @@ simple_strtod_int (const char *input_str, long double val = 0; unsigned int digits = 0; + bool found_digit = false; if (*input_str == '-') { @@ -476,7 +477,10 @@ simple_strtod_int (const char *input_str, { int digit = (**endptr) - '0'; - digits++; + found_digit = true; + + if (val || digit) + digits++; if (digits > MAX_UNSCALED_DIGITS) e = SSE_OK_PRECISION_LOSS; @@ -489,7 +493,8 @@ simple_strtod_int (const char *input_str, ++(*endptr); } - if (digits == 0) + if (! found_digit + && ! STREQ_LEN (*endptr, decimal_point, decimal_point_length)) return SSE_INVALID_NUMBER; if (*negative) val = -val; -- cgit v1.2.3-54-g00ecf