On Thu, Feb 12, 2004 at 06:44:25PM +0100, Roberto Gordo Saez wrote: > Package: libc6 > Version: 2.3.2.ds1-11 > Severity: important > > The function strtof does not work at all, it always returns garbage. > Many programs are silently broken by this bug. This small > example will return a random number, without using rand :-) > > #include <stdlib.h> > #include <stdio.h> > #include <stddef.h> > > int main (void) > { > printf ("%f\n", strtof ("5E+2", NULL)); > return 0; > } > > Actually, the value returned by strtof seems to come from a pointer > freely walking through the stack; declaring a new, unused variable > sometimes makes a different value returned, like in this case:
[EMAIL PROTECTED]:~% gcc -g -o stof stof.c -Wall stof.c: In function `main': stof.c:7: warning: implicit declaration of function `strtof' stof.c:7: warning: double format, different type arg (arg 2) Always, always use compiler warnings when looking at a problem like this one. According to stdlib.h strtof is only available in C99 mode. If I add -std=c99 the program works. If you add -D_GNU_SOURCE, it probably will work then also. At most the man page needs a note. It does already say: CONFORMING TO ANSI C describes strtod, C99 describes the other two functions. -- Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]