From owner-freebsd-current@FreeBSD.ORG Sun Jan 23 22:50:05 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3D57416A4CE; Sun, 23 Jan 2005 22:50:05 +0000 (GMT) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id 71E9343D45; Sun, 23 Jan 2005 22:50:04 +0000 (GMT) (envelope-from j@uriah.heep.sax.de) Received: from sax.sax.de (localhost [127.0.0.1]) by sax.sax.de (8.12.10/8.12.10) with ESMTP id j0NMo2Yu099828; Sun, 23 Jan 2005 23:50:02 +0100 (CET) (envelope-from j@uriah.heep.sax.de) Received: (from uucp@localhost) by sax.sax.de (8.12.10/8.12.10/Submit) with UUCP id j0NMo22v099826; Sun, 23 Jan 2005 23:50:02 +0100 (CET) (envelope-from j@uriah.heep.sax.de) Received: from uriah.heep.sax.de (localhost [127.0.0.1]) by uriah.heep.sax.de (8.13.1/8.13.1) with ESMTP id j0NMltgD034016; Sun, 23 Jan 2005 23:47:55 +0100 (MET) (envelope-from j@uriah.heep.sax.de) Received: (from j@localhost) by uriah.heep.sax.de (8.13.1/8.13.1/Submit) id j0NMltaD034015; Sun, 23 Jan 2005 23:47:55 +0100 (MET) (envelope-from j) Date: Sun, 23 Jan 2005 23:47:55 +0100 From: Joerg Wunsch To: Giorgos Keramidas Message-ID: <20050123224755.GK30862@uriah.heep.sax.de> References: <20050120205501.GA69123@nagual.pp.ru> <20050120211449.GC30862@uriah.heep.sax.de> <20050120214406.GA70088@nagual.pp.ru> <20050120222137.GE30862@uriah.heep.sax.de> <20050121230949.GA34313@VARK.MIT.EDU> <20050122113015.GV30862@uriah.heep.sax.de> <20050122171743.GB39943@nagual.pp.ru> <20050123143024.GA28604@gothmog.gr> <20050123211656.GB64754@nagual.pp.ru> <20050123221630.GB22234@gothmog.gr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050123221630.GB22234@gothmog.gr> User-Agent: Mutt/1.4.2.1i X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E X-GPG-Fingerprint: 5E84 F980 C3CA FD4B B584 1070 F48C A81B 69A8 5873 X-Spam-Status: No, score=-2.6 required=7.5 tests=AWL,BAYES_00 autolearn=ham version=3.0.1 X-Spam-Checker-Version: SpamAssassin 3.0.1 (2004-10-22) on uriah.heep.sax.de cc: Andrey Chernov cc: current@freebsd.org Subject: Re: Implementation errors in strtol() X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Joerg Wunsch List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Jan 2005 22:50:05 -0000 As Giorgos Keramidas wrote: > If errno is explicitly set (i.e. zeroed) by the calling program > immediately before strtol(), can we not be sure that it was, in > fact, strtol() that set it to any non-zero value? Andrey meant that an application shouldn't blindly assume that errno == ERANGE, as other extensions to the standard could allow setting errno to other values for other errors. However, this immediately reminded me of Steinbach's Guideline for System Programming. ;-) (-> fortune -m Steinbach) At least according to C99/Posix/SUSP, once you've caught conversion errors (by means of looking whether endptr had been advanced), and if you are sure that base had a legitimate value (as it is probably a hardcoded value in almost any practical application of strto*l), the only legitimate errno value remaining is ERANGE, as after a valid conversion and with a correct base value, there's no chance for EINVAL anymore. Sure, you can check whether errno != 0 && errno != ERANGE, but see Steinbach, what to do in that case? abort() ;-) I think Andreay always thought it the other way round, first test errno, and only if errno == 0, test endptr. But see above, testing errno for EINVAL can be completely skipped when done properly. That's why I think that the entire EINVAL thing is completely pointless. It would have only been meaningful in any way if SUSP had mandated it to be set in case of a conversion error (and even then, only applications that rely on SUSP extensions over C99 could have relied on it). -- cheers, J"org .-.-. --... ...-- -.. . DL8DTL http://www.sax.de/~joerg/ NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)