public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/13246] New: RFE: strtold: do not include uninitialized bytes when converting "NaN"
@ 2011-10-01 17:39 jim at meyering dot net
  2011-10-05 14:52 ` [Bug libc/13246] " schwab@linux-m68k.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: jim at meyering dot net @ 2011-10-01 17:39 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=13246

             Bug #: 13246
           Summary: RFE: strtold: do not include uninitialized bytes when
                    converting "NaN"
           Product: glibc
           Version: 2.14
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: jim@meyering.net
    Classification: Unclassified


strtold ("nan", NULL) appears to return a result that depends on the prior
state of the stack.  That non-determinism caused GNU sort to infloop, but we've
worked around this glibc-specific issue: http://debbugs.gnu.org/9612

Here's a little program to demonstrate the problem.
Note how the results differ with compilation options:

  #include <stdlib.h>
  #include <stdio.h>

  static char *
  fmt_nan (long double x)
  {
    unsigned int i;
    static char buf[33];
    unsigned char const *p = (unsigned char const *) &x;
    for (i = 0; i < sizeof x; i++)
      sprintf (buf + 2*i, "%02x", *p++);
    return buf;
  }

  int
  main ()
  {
    const char *q = "nan";
    long double x = strtold (q, NULL);
    printf ("%s\n", fmt_nan (x));

    x = 0;
    x = strtold (q, NULL);
    printf ("%s\n", fmt_nan (x));

    return 0;
  }

  $ gcc -O0 -Wall -Wextra -W /t/strtold-bogosity.c && ./a.out
  00000000000000c0ff7f400000000000
  00000000000000c0ff7f000000000000
  $ gcc -O1 -Wall -Wextra -W /t/strtold-bogosity.c && ./a.out
  00000000000000c0ff7f000000000000
  00000000000000c0ff7f000000000000

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-06-27 11:59 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-01 17:39 [Bug libc/13246] New: RFE: strtold: do not include uninitialized bytes when converting "NaN" jim at meyering dot net
2011-10-05 14:52 ` [Bug libc/13246] " schwab@linux-m68k.org
2011-10-05 22:10 ` bugdal at aerifal dot cx
2011-10-06  7:57 ` schwab@linux-m68k.org
2011-10-06  8:16 ` jakub at redhat dot com
2011-10-06  8:33 ` jim at meyering dot net
2011-10-06  8:46 ` jakub at redhat dot com
2011-10-06  9:31 ` jim at meyering dot net
2011-10-06  9:41 ` schwab@linux-m68k.org
2011-10-06  9:48 ` jim at meyering dot net
2011-10-06  9:57 ` jakub at redhat dot com
2011-10-06 12:40 ` bugdal at aerifal dot cx
2014-06-27 11:59 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).