Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Oct 2010 16:08:50 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Jilles Tjoelker <jilles@stack.nl>
Cc:        freebsd-standards@freebsd.org
Subject:   Re: standards/151316: lib/libc/string/strerror.c r1.9 breaks POSIX
Message-ID:  <20101009130850.GY2392@deviant.kiev.zoral.com.ua>
In-Reply-To: <201010091240.o99Ce7AM048178@freefall.freebsd.org>
References:  <201010091240.o99Ce7AM048178@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--ZplOxUIsrEyrgofR
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Oct 09, 2010 at 12:40:07PM +0000, Jilles Tjoelker wrote:
> The following reply was made to PR standards/151316; it has been noted by=
 GNATS.
>=20
> From: Jilles Tjoelker <jilles@stack.nl>
> To: Jeremy Huddleston <jeremyhu@apple.com>
> Cc: freebsd-gnats-submit@FreeBSD.org
> Subject: Re: standards/151316: lib/libc/string/strerror.c r1.9 breaks POS=
IX
> Date: Sat, 9 Oct 2010 14:37:31 +0200
>=20
>  On Fri, Oct 08, 2010 at 04:28:55PM +0000, Jeremy Huddleston wrote:
>  > >Number:         151316
>  > >Category:       standards
>  > >Synopsis:       lib/libc/string/strerror.c r1.9 breaks POSIX
> =20
>  > >Description:
>  > r1.9 of strerror.c did the following (from the changeslog)
> =20
>  > strerror()'s semantics have changed slightly such that an argument of
>  > 0 is now considered invalid and errno is set to EINVAL.
> =20
>  > This introduces a regression in SUS conformance.
> =20
>  Please explain why. As far as I understand, 0 is not a valid error
>  number, and therefore it is appropriate to set errno =3D EINVAL while
>  still returning a string.
> =20
>  Hints to 0 being an invalid error number are the requirement that all E*
>  constants from <errno.h> be positive and the requirement that no
>  POSIX-defined function shall set errno to 0.
> =20
>  If I'm wrong, please provide a reference such as to a specific section
>  in the standard.
> =20
>  In any case, this is of little practical effect since few programs check
>  the value of errno set by strerror(). If the patch is accepted,
>  sys_errlist[0] will probably be changed to "Unknown error: 0" so the
>  only difference is errno set by strerror().
> =20
>  > >How-To-Repeat:
> =20
>  > >Fix:
>  > In strerror.c's strerror_r
>  > -	if (errnum < 1 || errnum >=3D sys_nerr) {
>  > +	if (errnum < 0 || errnum >=3D sys_nerr) {
> =20
>  > And here's a man page change:
> =20
>  > @@ -110,7 +118,7 @@
>  >  .Er EINVAL
>  >  as a warning.
>  >  Error numbers recognized by this implementation fall in
>  > -the range 0 <
>  > +the range 0 <=3D
>  >  .Fa errnum
>  >  <
>  >  .Fa sys_nerr .

The often-used idiom is
	printf("Error %d %s\n", errno, strerror(errno));
In case of errno =3D=3D 0 you get
	Error 0: Unknown error
or something else depending on the order of evaluation of the arguments.

--ZplOxUIsrEyrgofR
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (FreeBSD)

iEYEARECAAYFAkywaWEACgkQC3+MBN1Mb4jlUwCfXzBX5T3YNOWkzRlnIDSBLySk
3T4AniFRVS+YGy+HDmy4/b3IGQgseC5j
=qBX5
-----END PGP SIGNATURE-----

--ZplOxUIsrEyrgofR--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101009130850.GY2392>