problem with atof / sscanf / strtof and float's range
Rich Felker
dalias at aerifal.cx
Thu Nov 30 03:28:18 UTC 2006
On Wed, Nov 29, 2006 at 11:31:39AM +0100, Mathias Krause wrote:
> Hi Developpers,
>
> I have a problem using the functions sscanf, atof and strtof of uClibc to
> convert a string to a float value.
>
> For example, I do the following to convert my huge string:
> --- code ---
> float myFloat = 0.0;
> char myString[] = {"9999999999999999999999999999999999999999999999999.9"};
> int ret = 0;
>
> ret = sscanf(myString, "%f", &myFloat);
> // myFloat = atof(myString);
> // myFloat = strtof(myString, NULL);
>
> printf("Return: %i\r\n", ret);
> printf("Float: %f\r\n", myFloat);
> --- end code ---
>
> If the Number in the String is not as big as in my example, everything
> works fine. But for such a big number, the application outputs
> --- output ---
> Return: 1
> Float: -0.000000
> --- output end ---
>
> so my question is: is it possible for me to detect the range overflow of
> my float? With standard libc sscanf would return 0 to indicate the error.
As far as I know this is simply a bug in uClibc. It puts arbitrary
limits on the size of the float strings it will read IIRC.
Rich
More information about the uClibc
mailing list