This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/3664] New: strtod handling of all-zeros numbers broken
- From: "jsm28 at gcc dot gnu dot org" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 6 Dec 2006 01:54:16 -0000
- Subject: [Bug libc/3664] New: strtod handling of all-zeros numbers broken
- Reply-to: sourceware-bugzilla at sourceware dot org
strtod_l.c contains a conditional which is never going to pass because it
requires both base == 16 and base != 16.
if ((c < L_('0') || c > L_('9'))
&& (base == 16 && (c < (CHAR_TYPE) TOLOWER (L_('a'))
|| c > (CHAR_TYPE) TOLOWER (L_('f'))))
#ifdef USE_WIDE_CHAR
&& c != (wint_t) decimal
#else
&& ({ for (cnt = 0; decimal[cnt] != '\0'; ++cnt)
if (decimal[cnt] != cp[cnt])
break;
decimal[cnt] != '\0'; })
#endif
&& (base == 16 && (cp == start_of_digits
|| (CHAR_TYPE) TOLOWER (c) != L_('p')))
&& (base != 16 && (CHAR_TYPE) TOLOWER (c) != L_('e')))
I believe the fix is to change "base == 16 &&" to "base != 16 ||" in both
places, "base != 16 &&" to "base == 16 ||", "c < (CHAR_TYPE) TOLOWER (L_('a'))"
to "(CHAR_TYPE) TOLOWER (c) < L_('a')" and likewise for 'f'.
The following test shows that this causes an actual bug.
#include <stdlib.h>
int
main(void)
{
const char *s = "0x";
char *ep;
double r = strtod(s, &ep);
if (r != 0)
abort();
if (ep != s + 1)
abort();
exit(0);
}
--
Summary: strtod handling of all-zeros numbers broken
Product: glibc
Version: 2.4
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: jsm28 at gcc dot gnu dot org
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=3664
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.