From owner-freebsd-bugs@FreeBSD.ORG Fri Jul 30 07:20:38 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6BF8116A4CE for ; Fri, 30 Jul 2004 07:20:38 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 604CE43D49 for ; Fri, 30 Jul 2004 07:20:38 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i6U7KENa069002 for ; Fri, 30 Jul 2004 07:20:14 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i6U7KDix069001; Fri, 30 Jul 2004 07:20:13 GMT (envelope-from gnats) Date: Fri, 30 Jul 2004 07:20:13 GMT Message-Id: <200407300720.i6U7KDix069001@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Steven Smith Subject: Re: misc/69788: The processing result of strtoul() cannot judge whether it is an error. X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Steven Smith List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jul 2004 07:20:38 -0000 The following reply was made to PR misc/69788; it has been noted by GNATS. From: Steven Smith To: Takayuki Sakuma Cc: freebsd-gnats-submit@FreeBSD.org, sos22@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 --liOOAslEiF7prFVr 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= or(errno)); >=20 > result: > ul=3D4294967295,*p=3D0,errno=3D22(Unknown error: 0) In my tests, strtoul correctly leaves errno at 0: errno=3D0; 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= )); =20 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@cantab.net. --=20 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. --liOOAslEiF7prFVr Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFBCfTqO4S8/gLNrjcRAjpOAJ9NjV/uXuyDyTVjZgSo3vO3NubF2gCfVHo6 wmgzDCyCrVNPkA9VvQTbwi8= =etGX -----END PGP SIGNATURE----- --liOOAslEiF7prFVr--