This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Set errno in strtof variants when conversion from double overflows


Patch has been applied.

Thanks,

-- Jeff J.

----- Original Message -----
> Hi all,
> 
> I've been investigating some libstdc++ execution failures on newlib
> bare-metal targets, in particular arm-none-eabi and aarch64-none-elf.
> In particular:
> 21_strings/basic_string/numeric_conversions/char/stof.cc
> 21_strings/basic_string/numeric_conversions/wchar_t/stof.cc
> 
> 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?
> 
> Thanks,
> Kyrill
> 
> 2016-12-15  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
> 
>      * libc/stdlib/strtod.c (strtof_l): Set errno to ERANGE when double to
>      float conversion results in infinity.
>      (strtof): Likewise.
>      * libc/stdlib/wcstod.c (wcstof_l): Likewise.
>      (wcstof): Likewise.
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]