summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-06-22 02:12:32 +0100
committerPádraig Brady <P@draigBrady.com>2015-06-22 02:21:02 +0100
commitbc9d16b79f4e8c25e13be63f846cfd7152b65da1 (patch)
treef59de970119880a9a860a2ca258c4ad64677a0c3 /src
parenta3c3e1e9e6d2d953692f1eb24efa9ac7c7448044 (diff)
downloadcoreutils-bc9d16b79f4e8c25e13be63f846cfd7152b65da1.tar.xz
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.
Diffstat (limited to 'src')
-rw-r--r--src/numfmt.c9
1 files changed, 7 insertions, 2 deletions
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;