Mercurial > hg > octave-kai > gnulib-hg
changeset 13487:4ccc551d5cb6
strtod: fix bug in replacement function on AIX
* lib/strtod.c (strtod): Special case broken "0x" parse in
underlying strtod.
* tests/test-strtod.c (main): Document AIX 7.1 bugs.
* doc/posix-functions/strtod.texi (strtod): Likewise.
Reported by Rainer Tammer.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Thu, 29 Jul 2010 17:32:23 -0600 |
parents | 8524cbf0a405 |
children | a3a7f9627d7a |
files | ChangeLog doc/posix-functions/strtod.texi lib/strtod.c tests/test-strtod.c |
diffstat | 4 files changed, 36 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-07-30 Eric Blake <eblake@redhat.com> + + strtod: fix bug in replacement function on AIX + * lib/strtod.c (strtod): Special case broken "0x" parse in + underlying strtod. + * tests/test-strtod.c (main): Document AIX 7.1 bugs. + * doc/posix-functions/strtod.texi (strtod): Likewise. + Reported by Rainer Tammer. + 2010-07-30 Bruno Haible <bruno@clisp.org> mbrlen: Fix cross-compilation guess for AIX.
--- a/doc/posix-functions/strtod.texi +++ b/doc/posix-functions/strtod.texi @@ -31,7 +31,7 @@ @item This function returns the wrong end pointer for @samp{-0x} on some platforms: -glibc 2.4, MacOS X 10.3, FreeBSD 6.2, Cygwin < 1.5.25-11. +glibc 2.4, MacOS X 10.3, FreeBSD 6.2, AIX 7.1, Cygwin < 1.5.25-11. @item This function returns +0.0 (not -0.0) for @samp{-0} on some platforms: @@ -43,7 +43,7 @@ @item This function fails to parse @samp{NaN()} on some platforms: -glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Cygwin < 1.5.25-11, mingw. +glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 7.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Cygwin < 1.5.25-11, mingw. @item This function fails to parse @samp{NaN(@var{n-char-sequence})} on some @@ -53,7 +53,7 @@ @item This function parses @samp{NaN(@var{n-char-sequence})}, but returns the wrong end pointer on some platforms: -glibc-2.4, AIX 5.1. +glibc-2.4, AIX 7.1. @item This function fails to parse C99 hexadecimal floating point on some
--- a/lib/strtod.c +++ b/lib/strtod.c @@ -215,10 +215,15 @@ 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 starts with "0x", consume the "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 + end = s + 1; + } s = end; }
--- a/tests/test-strtod.c +++ b/tests/test-strtod.c @@ -386,7 +386,7 @@ 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 (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, AIX 7.1 */ ASSERT (errno == 0); } { @@ -408,7 +408,7 @@ result = strtod (input, &ptr); ASSERT (result == 0.0); ASSERT (!!signbit (result) == !!signbit (-zero)); /* MacOS X 10.3, FreeBSD 6.2, IRIX 6.5, OSF/1 4.0 */ - ASSERT (ptr == input + 2); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2 */ + ASSERT (ptr == input + 2); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, AIX 7.1 */ ASSERT (errno == 0); } { @@ -419,7 +419,7 @@ 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 (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, AIX 7.1 */ ASSERT (errno == 0); } { @@ -430,7 +430,7 @@ 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 (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, AIX 7.1 */ ASSERT (errno == 0); } { @@ -441,7 +441,7 @@ 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 (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, AIX 7.1 */ ASSERT (errno == 0); } { @@ -452,7 +452,7 @@ 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 (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, AIX 7.1 */ ASSERT (errno == 0); } { @@ -463,7 +463,7 @@ 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 (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, AIX 7.1 */ ASSERT (errno == 0); } { @@ -474,7 +474,7 @@ 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 (ptr == input + 1); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, AIX 7.1 */ ASSERT (errno == 0); } { @@ -665,8 +665,8 @@ worrying about. */ ASSERT (!!signbit (result1) != !!signbit (result2)); /* glibc-2.3.6, IRIX 6.5, OSF/1 5.1, mingw */ # endif - ASSERT (ptr1 == input + 6); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ - ASSERT (ptr2 == input + 6); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ + ASSERT (ptr1 == input + 6); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 7.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ + ASSERT (ptr2 == input + 6); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 7.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ ASSERT (errno == 0); #else ASSERT (result1 == 0.0); @@ -686,7 +686,7 @@ result = strtod (input, &ptr); #if 1 /* All known CPUs support NaNs. */ ASSERT (isnand (result)); /* OpenBSD 4.0, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ - ASSERT (ptr == input + 6); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ + ASSERT (ptr == input + 6); /* glibc-2.3.6, MacOS X 10.3, FreeBSD 6.2, OpenBSD 4.0, AIX 7.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ ASSERT (errno == 0); #else ASSERT (result == 0.0); @@ -715,8 +715,8 @@ worrying about. */ ASSERT (!!signbit (result1) != !!signbit (result2)); /* glibc-2.3.6, IRIX 6.5, OSF/1 5.1, mingw */ # endif - ASSERT (ptr1 == input + 7); /* glibc-2.3.6, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ - ASSERT (ptr2 == input + 7); /* glibc-2.3.6, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ + ASSERT (ptr1 == input + 7); /* glibc-2.3.6, OpenBSD 4.0, AIX 7.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ + ASSERT (ptr2 == input + 7); /* glibc-2.3.6, OpenBSD 4.0, AIX 7.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, mingw */ ASSERT (errno == 0); #else ASSERT (result1 == 0.0); @@ -756,8 +756,8 @@ double result; errno = 0; result = strtod (input, &ptr); - ASSERT (result == 1.0); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */ - ASSERT (ptr == input + 3); /* NetBSD 3.0, OpenBSD 4.0, AIX 5.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */ + ASSERT (result == 1.0); /* NetBSD 3.0, OpenBSD 4.0, AIX 7.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */ + ASSERT (ptr == input + 3); /* NetBSD 3.0, OpenBSD 4.0, AIX 7.1, HP-UX 11.11, IRIX 6.5, OSF/1 5.1, Solaris 10, mingw */ ASSERT (errno == 0); } {