From owner-freebsd-current@FreeBSD.ORG Thu Jan 20 21:20:07 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 93B7C16A4CE; Thu, 20 Jan 2005 21:20:07 +0000 (GMT) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id C43FE43D53; Thu, 20 Jan 2005 21:20:06 +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 j0KLK5Yu054488; Thu, 20 Jan 2005 22:20:05 +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 j0KLK50f054487; Thu, 20 Jan 2005 22:20:05 +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 j0KLEnio034096; Thu, 20 Jan 2005 22:14:49 +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 j0KLEnXg034095; Thu, 20 Jan 2005 22:14:49 +0100 (MET) (envelope-from j) Date: Thu, 20 Jan 2005 22:14:49 +0100 From: Joerg Wunsch To: current@FreeBSD.ORG Message-ID: <20050120211449.GC30862@uriah.heep.sax.de> References: <20050120192324.GA30862@uriah.heep.sax.de> <20050120205501.GA69123@nagual.pp.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20050120205501.GA69123@nagual.pp.ru> 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=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: bde@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: Thu, 20 Jan 2005 21:20:07 -0000 As Andrey Chernov wrote: > > While the standard explicitly states that empty (or > > whitespace-only) input strings cause an empty subject sequence, > > which will in turn cause no conversion to be performed, single > > signs ("+" or "-") would contain a non-empty subject sequence, so > > a conversion has to take place. FreeBSD erroneously returns > > EINVAL in that case. As EINVAL is > Just what is eye-catching: > +- can't be compared to whitespace at all. Whitespace is not subject > sequence (2) but initial sequence (1) according to POSIX. That's correct, and doesn't contradict to what I wrote. It only means there's no difference in " " vs. "". > Moreover, POSIX clearly allows EINVAL for strtol(): > "If no conversion could be performed, 0 shall be returned and errno > may be set to [EINVAL]" Yes, I know. Anyway, how could POSIX (or the Single UNIX Specification, for that matter) possibly contradict to the C standard? In reading the C standard, I get the impression that for functions where the standard describes their possible modifications to errno, no further modifications are permissible. Paragraph 3 of section 7.5 »Errors « says: ``The value of errno is zero at program startup, but is never set to zero by any library function.170) The value of errno may be set to nonzero by a library function call whether or not there is an error, provided the use of errno is not documented in the description of the function in this International Standard.'' I read this as an explicit prohibition of setting errno to anything else (as strtol has a documented behaviour for setting errno), and just wondered how POSIX could get away with its (IMHO) violation of that statement. Still, my major point was that "0x" sequences are falsely rejected as conversion errors, and that strings consisting solely of a plus or minus sign should not throw an error either, as I read the C standard. I confess that I'm operating on a prerelease version of the C standard, in case that matters. -- cheers, J"org .-.-. --... ...-- -.. . DL8DTL http://www.sax.de/~joerg/ NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)