From owner-freebsd-bugs@FreeBSD.ORG Fri Jul 30 07:31:34 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 B2F0D16A4CE for ; Fri, 30 Jul 2004 07:31:34 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id A8CD343D41 for ; Fri, 30 Jul 2004 07:31:34 +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 i6U7UP1g069455 for ; Fri, 30 Jul 2004 07:30:25 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i6U7UP3O069454; Fri, 30 Jul 2004 07:30:25 GMT (envelope-from gnats) Date: Fri, 30 Jul 2004 07:30:25 GMT Message-Id: <200407300730.i6U7UP3O069454@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: SAKUMA takayuki 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: SAKUMA takayuki List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jul 2004 07:31:34 -0000 The following reply was made to PR misc/69788; it has been noted by GNATS. From: SAKUMA takayuki To: sos22@cantab.net 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 16:24:42 +0900 (JST) > In my tests, strtoul correctly leaves errno at 0: > errno=0; > ul = strtoul("4294967295", &p, 10); > o_errno = errno; > printf("ul=%lu,*p=%x,errno=%d(%s)\n", ul, *p, o_errno,strerror(errno)); > > gives the result ``ul=4294967295,*p=0,errno=0(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). ul = strtoul("4294967296", &p, 10); ul = strtoul("4294967295", &p, 10); 2nd strtoul() will success, but errno == ERANGE. Is it necessary to set errno as 0 before calling 2nd strtoul() ? ------ takayuki@finet.fujitsu.com