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

Kyrill Tkachov kyrylo.tkachov@foss.arm.com
Mon Dec 19 10:16:00 GMT 2016


On 16/12/16 18:27, Corinna Vinschen wrote:
> On Dec 16 11:30, Jeff Johnston wrote:
>> It can go, but I would imagine it is doing no harm if the compiler has any
>> smarts at all.  I'll remove it.
> Yeah, I didn't worry about the compiler, I was just thinking of code
> cleanup.  Did the same to wcstod.c.

Thanks Jeff and Corinna.
I was testing a patch to delete these, but you beat me to it.

Kyrill

>
> Thanks,
> Corinna
>
>
>> -- Jeff J.
>>
>> ----- Original Message -----
>>> On Dec 15 16:47, Kyrill Tkachov wrote:
>>>> diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c
>>>> index e908fcb..f82f507 100644
>>>> --- a/newlib/libc/stdlib/strtod.c
>>>> +++ b/newlib/libc/stdlib/strtod.c
>>>> @@ -1293,9 +1293,14 @@ _DEFUN (strtod, (s00, se),
>>>>   float
>>>>   strtof_l (const char *__restrict s00, char **__restrict se, locale_t loc)
>>>>   {
>>>> -  double retval = _strtod_l (_REENT, s00, se, loc);
>>>> -  if (isnan (retval))
>>>> +  double val = _strtod_l (_REENT, s00, se, loc);
>>>> +  if (isnan (val))
>>>>       return nanf (NULL);
>>>> +  float retval = (float) val;
>>>> +#ifndef NO_ERRNO
>>>> +  if (isinf (retval) && !isinf (val))
>>>> +    _REENT->_errno = ERANGE;
>>>> +#endif
>>>>     return (float)retval;
>>>              ^^^^^^^
>>> Shouldn't this cast go, now that retval is already float?
>>>
>>>
>>> Corinna



More information about the Newlib mailing list