[PATCH] Set errno in strtof variants when conversion from double overflows
Thu Dec 15 16:47:00 GMT 2016
I've been investigating some libstdc++ execution failures on newlib bare-metal targets, in particular arm-none-eabi and aarch64-none-elf.
These tests perform a conversion from string to a float and end up mapping down to the strtof/wcstof C functions.
They create a string from a large number that is representable in double precision but not in single precision and expect
strtof to return infinity and set errno to ERANGE so that libstdc++ can throw an exception.
But the implementation of strtof uses strtod internally to convert the string to a double and then cast the result to a float.
This works for getting the infinity result but doesn't set errno properly.
This patch adds a check after the conversion to see if the cast ended up generating an infinity from a non-infinity and sets errno
in that case.
With this patch the aforementioned tests pass on arm-none-eabi and aarch64-none-elf.
Is this ok?
If so, can someone please commit it on my behalf?
2016-12-15 Kyrylo Tkachov <email@example.com>
* libc/stdlib/strtod.c (strtof_l): Set errno to ERANGE when double to
float conversion results in infinity.
* libc/stdlib/wcstod.c (wcstof_l): Likewise.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2241 bytes
Desc: not available
More information about the Newlib