bug-glibc
[Top][All Lists]
Advanced

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

Bug inside the function strtold()


From: Ivano Primi
Subject: Bug inside the function strtold()
Date: Wed, 3 Dec 2003 15:21:01 +0100 (MET)

I have just found a bug in the package glibc-2.3.2. This bug
concerns the function strtold(), as showed below. If you pass
to strtold() the string "42.00000000000000000001" (with 19 zeros or more)
then strtold() will return 0 instead of 42 (as you could expect).
This bug is strange because the function strtod() works fine:

strtod ("42.00000000000000000001", &endptr)

return 42, just as expected.
In the following lines you can find the source code which shows the
bug and the results which i have obtained on my machine after building
it.

---------------------- Source ----------------------------------

#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 buff[100];
  char* endptr;
  long double x;

  errno = 0;
  printf ("Give me a number: \t");
  fgets (buff, 100, stdin);
  x = strtold (buff, &endptr);
  if ( endptr == buff && 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 ("This is the number you have entered: %.20Lf\n", x);
      printf ("Bye !\n");
      return 0;
    }
}

------------------------ Tests -------------------------------------

Script started on Wed 03 Dec 2003 02:59:15 PM CET
TIPO DI MACCHINA : i386-linux HOSTNAME : diablo.iac.rm.cnr.it
diablo.iac.rm.cnr.it 1 > ./test
Give me a number:       42.0000000000000000001
This is the number you have entered: 42.00000000000000000000
Bye !
diablo.iac.rm.cnr.it 2 > ./test
Give me a number:       42.00000000000000000001
This is the number you have entered: 0.00000000000000000000
Bye !
diablo.iac.rm.cnr.it 3 > ./test
Give me a number:       42.0000000000000000000001
This is the number you have entered: 0.00000000000000000000
Bye !
diablo.iac.rm.cnr.it 4 > ^D
Script done on Wed 03 Dec 2003 03:00:27 PM CET

--------------------Info about the version of glibc ----------------------

Name        : glibc                        Relocations: (not relocateable)
Version     : 2.3.2                             Vendor: Red Hat, Inc.
Release     : 11.9                          Build Date: Fri 14 Mar 2003 
01:48:24 AM CET
Install Date: Fri 20 Jun 2003 10:07:01 AM CEST      Build Host: 
daffy.perf.redhat.com
Group       : System Environment/Libraries   Source RPM: 
glibc-2.3.2-11.9.src.rpm
Size        : 11183614                         License: LGPL
Signature   : DSA/SHA1, Fri 14 Mar 2003 01:56:54 AM CET, Key ID 219180cddb42a60e
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Summary     : The GNU libc libraries.
Description :
The glibc package contains standard libraries which are used by
multiple programs on the system. In order to save disk space and
memory, as well as to make upgrading easier, common system code is
kept in one place and shared between programs. This particular package
contains the most important sets of shared libraries: the standard C
library and the standard math library. Without these two libraries, a
Linux system will not function.





reply via email to

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