bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug inside the function strtold()


From: Petter Reinholdtsen
Subject: Re: Bug inside the function strtold()
Date: Tue, 20 Jul 2004 11:04:21 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (usg-unix-v)

[Ivano Primi, 2003-12-03]
> I have just found a bug in the package glibc-2.3.2. This bug
> concerns the function strtold(), as showed below.

I rewrote your test program to be more self contained, and tested it
on Debian/unstable.  It fails here too.

Perhaps you want to report it to the glibc bugzilla available from
<URL:http://sources.redhat.com/bugzilla/>?

/*
 * Demonstrate bug in strtold() in glibc.  The last two number strings
 * converts to 0, not 42 as it should.
 * Based on code from Ivano Primi and modified by Petter Reinholdtsen.
 */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

extern int errno;
extern long double strtold(const char *nptr, char **endptr);

int main (void)
{
  char *numbers[] = {
    "42.0000000000000000001",
    "42.00000000000000000001",
    "42.0000000000000000000001",
    };
  char* endptr;
  long double x;
  int i;

  errno = 0;
  for (i = 0; i < 3; i++) {
    x = strtold (numbers[i], &endptr);
    if ( endptr == numbers[i] && x == 0 )
      {
        fprintf (stderr, " *** Unagreable input\n");
        return 1;
      }
    else if ( errno != 0 )
      {
        if ( x == 0 )
          fprintf (stderr, " *** Underflow\n");
        else
          fprintf (stderr, " *** Overflow\n");
        return 2;
      }
    else
      {
        printf ("String '%s' converts to long double %.20Lf\n", numbers[i], x);
      }
  }
  return 0;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]