tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: strerror(0) POSIX compliance



On Thu, Mar 24, 2016 at 09:56:47AM -0400, Greg Troxel wrote:
> 
> Joerg Sonnenberger <joerg%britannica.bec.de@localhost> writes:
> 
> > On Thu, Mar 24, 2016 at 12:49:31PM +0100, Kamil Rytarowski wrote:
> >> -----BEGIN PGP SIGNED MESSAGE-----
> >> Hash: SHA256
> >> 
> >> POSIX extension to ISO C says:
> >> 
> >> [CX] [Option Start] If the value of errnum is a valid error number,
> >> the message string shall indicate what error occurred; if the value of
> >> errnum is zero, the message string shall either be an empty string or
> >> indicate that no error occurred; otherwise, if these functions
> >> complete successfully, the message string shall indicate that an
> >> unknown error occurred. [Option End]
> >> 
> >> http://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html
> >> 
> >> Currently we hardcode the following text:
> >>         "Undefined error: 0",                   /*  0 - ENOERROR */
> >
> > I find the rationale for the change in behavior quite questionable and
> > any code depending on it is IMO broken. But I don't really care about
> > changing the string.
> 
> Why do you find it questionable?  If POSIX says the string must be empty
> or indicate there is no error, what's wrong with following POSIX?
> 
> (I agree that calling strerror(0) is odd and a likely sign of a bug, but
> that's separate from complying with standards when compliance isn't
> harmful.)

0 is not a valid error code. Hint: there is no entry in errno.h for it.
As such, 0 as argument for strerror is outside the input range. The
whole change introduced something logically inconsistent for the sake of
badly written code. It is not strong enough an issue to adopt a
different text, but the original change remains just moronic, just like
code depending on it.

Joerg


Home | Main Index | Thread Index | Old Index