|
Message-ID: <20170614172641.GG1627@brightrain.aerifal.cx> Date: Wed, 14 Jun 2017 13:26:41 -0400 From: Rich Felker <dalias@...c.org> To: Florian Weimer <fweimer@...hat.com> Cc: Xiaowei Zhan <zhanxw@...il.com>, musl@...ts.openwall.com Subject: Re: Different behavior (strtod) between musl and glibc On Wed, Jun 14, 2017 at 03:44:34PM +0200, Florian Weimer wrote: > Xiaowei Zhan <zhanxw@...il.com> writes: > > > I notice that when pass a non-numeric char to strtod, musl will set > > errno to non-zero, but glibc will set errno to zero. I am curious why > > this difference exists, and whether it is necessary to make strtod in > > musl behave similarly to glibc. > > I think glibc leaves errno at zero; it does not set it. For input which > cannot be converted, this seems to be the behavior mandated by C11. > POSIX describes the EINVAL value as an extension to the C standard. > glibc does not appear to implement this extension. > > So both behaviors are correct. CX is a normative requirement for POSIX conformance; it indicates a requirement beyond (but not conflicting with) the C requirements for an interface defined by C. However, it's a "may fail", not a "shall fail", so the error is optional, and thus you're right that both musl and glibc are correct on the matter. I think you're also correct that glibc leaves errno alone in this case. Setting it to 0 would be non-conforming. The implementation is never permitted to set errno to 0 except at initial program entry. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.