Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 41386 - strtof function is broken
Summary: strtof function is broken
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: High critical (vote)
Assignee: Please assign to toolchain
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-12 09:05 UTC by Ragnar Hojland Espinosa
Modified: 2004-02-12 17:46 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ragnar Hojland Espinosa 2004-02-12 09:05:36 UTC
Just found out the reason of mysterious data corruptions we've been having:

(tested with glibc 2.3.2-r9 and glibc-2.3.3_pre20040207 compiled with 
gcc-3.3.2-r7)

#include <stdlib.h>
main()
{
   printf ("%f\n", strtof ("+5.7344E+02", 0));
   return 0;
}

prints:
0.000000

and

#include <stdlib.h>
main()
{
   char foo;
   printf ("%f\n", strtof ("+5.7344E+02", 0));
   return 0;
}

prints:
245504.625029
Comment 1 SpanKY gentoo-dev 2004-02-12 09:30:59 UTC
works over here ... maybe your CFLAGS are too aggressive ?  you neglected to provide `emerge info` so i have no idea

heres my setup:
Portage 2.0.50-r1 (default-x86-1.4, gcc-3.3.2, glibc-2.3.3_pre20040207-r0, 2.6.3-rc2)
CFLAGS="-pipe -march=pentium4 -O2 -frename-registers -fomit-frame-pointer -mfpmath=sse -mmmx -msse -msse2 -fdelete-null-pointer-checks -funroll-loops -ffast-math -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"
Comment 2 Ragnar Hojland Espinosa 2004-02-12 09:45:09 UTC
And here mine:

Portage 2.0.49-r18 (default-x86-1.4, gcc-3.3.2, glibc-2.3.3_pre20040207-r0, 2.6.2)
CFLAGS="-O2 -mcpu=i686 -pipe"

Wouldnt think its too aggressive ;)  A coworker just reproduced it in debian, and I did also on RHAS 2.1
Comment 3 SpanKY gentoo-dev 2004-02-12 10:24:49 UTC
hmm, well here's what i get on my different boxes using your test cases ... i guess i lied about getting the right answer ;)

i tested on a bunch of different archs/glibc (including 2.2.5) here and they all produce diff answers (but none the right one :D)

perhaps this is useful:
http://mail.gnu.org/archive/html/bug-glibc/2003-11/msg00119.html
Comment 4 bartron 2004-02-12 17:04:17 UTC
  It's not a bug...

  gcc does not see a prototype for `strtof()' and so assumes the
retval is int (try to recompile with `-Wall').  Correct way is to 
compile with `-std=c99' (or manually define "__USE_ISOC99" in case
gcc is too old).
Comment 5 SpanKY gentoo-dev 2004-02-12 17:46:16 UTC
i saw that define in the stdlib.h file and when i tried to do #define __USE_ISOC99, i'd still get warnings when compiling with -Wall

guess i must have mistyped the define when i last tried it ;)