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


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

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

Attachment: signature.asc
Description: PGP signature


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