[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] strtod: fix replacement bug on AIX.
From: |
Eric Blake |
Subject: |
[PATCH] strtod: fix replacement bug on AIX. |
Date: |
Thu, 29 Jul 2010 17:35:38 -0600 |
* lib/strtod.c (strtod): Special case broken "0x" parse in
underlying strtod.
Reported by Rainer Tammer.
Signed-off-by: Eric Blake <address@hidden>
---
> test-strtod.c:389: assertion failed
> >
> > {
> > const char input[] = "0x";
> > char *ptr;
> > double result;
> > errno = 0;
> > result = strtod (input, &ptr);
> > ASSERT (result == 0.0);
> > ASSERT (!signbit (result));
> > -> ASSERT (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3,
> > FreeBSD 6.2 */
> > ASSERT (errno == 0);
> > }
I'm guessing the bug is that your underlying strtod misparses "0x";
whereas glibc correctly consumes just the "0", not all platforms
do. While I haven't tested this on a platform where it matters,
I think this will do the trick.
ChangeLog | 7 +++++++
lib/strtod.c | 13 +++++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7f1c52e..11641cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-07-29 Eric Blake <address@hidden>
+
+ strtod: fix replacement bug on AIX.
+ * lib/strtod.c (strtod): Special case broken "0x" parse in
+ underlying strtod.
+ Reported by Rainer Tammer.
+
2010-02-17 Eric Blake <address@hidden>
manywarnings: add more warnings
diff --git a/lib/strtod.c b/lib/strtod.c
index 83b858a..7035adc 100644
--- a/lib/strtod.c
+++ b/lib/strtod.c
@@ -215,10 +215,15 @@ strtod (const char *nptr, char **endptr)
if (c_isdigit (s[*s == '.']))
{
- /* If a hex float was converted incorrectly, do it ourselves. */
- if (*s == '0' && c_tolower (s[1]) == 'x' && end <= s + 2
- && c_isxdigit (s[2 + (s[2] == '.')]))
- num = parse_number (s + 2, 16, 2, 4, 'p', &end);
+ /* If a hex float was converted incorrectly, do it ourselves.
+ If the string was exactly "0x", consume just "0" ourselves. */
+ if (*s == '0' && c_tolower (s[1]) == 'x' && end <= s + 2)
+ {
+ if (c_isxdigit (s[2 + (s[2] == '.')]))
+ num = parse_number (s + 2, 16, 2, 4, 'p', &end);
+ else if (!s[2])
+ end = s + 1;
+ }
s = end;
}
--
1.7.2
- Re: M4 1.4.14 on AIX 7.1BETA, Eric Blake, 2010/07/29
- Re: M4 1.4.14 on AIX 7.1BETA, Rainer Tammer, 2010/07/29
- strtod [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/29
- [PATCH] strtod: aid debugging, Eric Blake, 2010/07/29
- Re: strtod [was: M4 1.4.14 on AIX 7.1BETA], Rainer Tammer, 2010/07/29
- Re: strtod [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/29
- Re: strtod [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/29
- Message not available
- Message not available
- Message not available
- Re: strtod [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/29
- Message not available
- Re: strtod [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/29
- [PATCH] strtod: fix replacement bug on AIX.,
Eric Blake <=
- Re: strtod [was: M4 1.4.14 on AIX 7.1BETA], Rainer Tammer, 2010/07/30
- Re: strtod [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/30
- Re: strtod [was: M4 1.4.14 on AIX 7.1BETA], Rainer Tammer, 2010/07/30
- Message not available
- Re: c-stack [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/29
- Re: c-stack [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/29
- Message not available
- Re: regex [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/29
- Re: regex [was: M4 1.4.14 on AIX 7.1BETA], Paolo Bonzini, 2010/07/29
- Re: regex [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/29
- Re: regex [was: M4 1.4.14 on AIX 7.1BETA], Paolo Bonzini, 2010/07/29
- Re: regex [was: M4 1.4.14 on AIX 7.1BETA], Eric Blake, 2010/07/30