This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/3664] New: strtod handling of all-zeros numbers broken


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]