misc/69788: The processing result of strtoul() cannot judge whether it is an error.

Steven Smith sos22 at cantab.net
Fri Jul 30 00:20:38 PDT 2004

The following reply was made to PR misc/69788; it has been noted by GNATS.

From: Steven Smith <sos22 at cantab.net>
To: Takayuki Sakuma <takayuki at finet.fujitsu.com>
Cc: freebsd-gnats-submit at FreeBSD.org, sos22 at srcf.ucam.org
Subject: Re: misc/69788: The processing result of strtoul() cannot judge whether it is an error.
Date: Fri, 30 Jul 2004 08:12:42 +0100

 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 >         errno=3D0;
 >         ul =3D strtoul("4294967295", &p, 10);
 >         printf("ul=3D%lu,*p=3D%x,errno=3D%d(%s)\n", ul, *p, errno, strerr=
 > result:
 > ul=3D4294967295,*p=3D0,errno=3D22(Unknown error: 0)
 In my tests, strtoul correctly leaves errno at 0:
 	ul =3D strtoul("4294967295", &p, 10);
 	o_errno =3D errno;=09
 	printf("ul=3D%lu,*p=3D%x,errno=3D%d(%s)\n", ul, *p, o_errno,strerror(errno=
 gives the result ``ul=3D4294967295,*p=3D0,errno=3D0(Unknown error: 0)'', as
 expected.  The problem with the original test case is that strerror()
 is setting errno to EINVAL (because 0 isn't a valid error number)
 before errno is pushed on the stack for printf (the order in which
 function arguments are evaluated is undefined in C).
 Steven Smith,
 sos22 at cantab.net.
 One day, I'm going to get an Alice-bot to answer all my email for me,
 and see how long it takes people to notice.
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 Version: GnuPG v1.2.4 (FreeBSD)

More information about the freebsd-bugs mailing list