Re: strtold does not set errno when it should
Corinna Vinschen <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Hi Bruno, On Dec 16 11:05, Bruno Haible wrote: > Hi Corinna, > > > The code for strtold is almost verbatim taken from > > > > https://github.com/jwiegley/gdtoa.git > > > > There haven't been any patches upstream. > > Probably that's because the code is good enough for ISO C compliance; > however, POSIX [1] adds the "ERANGE upon underflow" requirement, > whereas ISO C only has an "ERANGE upon overflow" requirement. > > [1] <https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtod.html> > > > diff --git a/newlib/libc/stdlib/strtodg.c b/newlib/libc/stdlib/strtodg.c > > index 013315946c1b..d6fb26ad3b45 100644 > > --- a/newlib/libc/stdlib/strtodg.c > > +++ b/newlib/libc/stdlib/strtodg.c > > @@ -1091,6 +1091,10 @@ _strtodg_l (struct _reent *p, const char *s00, char **se, FPI *fpi, Long *exp, > > irv |= STRTOG_Underflow; > > } > > } > > +#ifndef NO_ERRNO > > + if (irv & STRTOG_Underflow) > > + errno = ERANGE; > > +#endif > > if (se) > > *se = (char *)s; > > if (sign) > > > > which seems to do the trick. But, does it make sense? If not, I'd > > really appreciate a patch. > > I think it goes in the right direction. > > It can be improved a bit, though: The existing code for overflow is careful > to do the errno stuff only when STRTOG_Overflow is being set/added. I.e. > keep this overflow/underflow handling out of the main path, in order not > to slow down the 99.99% of the cases that don't need it. > > My attempt to do this would look like the attached patch. Untested. That looks good to me and the result is the expected one. If nobody complains in the next few hours, I'll check this in. I *think* as of yet Cygwin is the only user of this code anyway. Thanks! Corinna -- Corinna Vinschen Cygwin Maintainer Red Hat
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl33XrkACgkQ9TYGna5E T6B3/BAAhAjka6tSL639DnCuIdr7yQg1NDRMYONAFoDHw7Hb8/AU4aoo1AAFnftR /f3wxTVNhWUH9EJ3FwAPkagbbHVN8RtJdoZM9FzkeOuYXtlOmfzGCLT58amqUqNc 2inIYMHywW/J5u93BIvPKhKYOf994NT1SSOIZkKX8xwVxYfG7IFgzMI3YrufJxKY 7N/cgAOeR0SiE1dkfk3ThV/KSo9aFyESZccOxcbZBWql2fe5IRAXkiezOx1n8t4q TRJIVZJrZoo03JQiy3e8r2LgJn7lylyoqpo+ZR9o12LuNiVqume1g82uqlVIfPJm UljX4jR+rYAKgS01GQ7HVRAKlYuIfKSEbwvYn7rSLA9t/Kq4AJY2NVQI122L9yGd w8C+jkqodWrdOMB6jVLaT4T7YjwGBXx+q0GqXnDxpkXkSUCrwT9Q4R652OBDtJyZ cjNHhOqGQNtNDBJcH73aKl4L4r/WtZ6ME5Vdjdy8sqnQvDkcWaR+Nbs3ZobdDtb8 EKysTcJcz8MTdZiBf9OOmCctUlSKGsYhQE5OTmOc4c/2w3gBtFXlmuHntmqiUmNT Wn4WigVqCD0ZGT8laBXJtzRUQk4A6dSOZgu+XfiP6vsF5M3hwDYNngHEyNogFPVj ye1MVn1f1/7xglyg4uslLQRZRf8MGep+8bDzGmEZ5gYxHp38kFc= =03Rv -----END PGP SIGNATURE-----