From owner-freebsd-current@FreeBSD.ORG Fri Jan 21 14:50:11 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 96FED16A4CE; Fri, 21 Jan 2005 14:50:11 +0000 (GMT) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id E07AA43D46; Fri, 21 Jan 2005 14:50:10 +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 j0LEo9Yu007200; Fri, 21 Jan 2005 15:50:09 +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 j0LEo93a007199; Fri, 21 Jan 2005 15:50:09 +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 j0LEjXOg059576; Fri, 21 Jan 2005 15:45:33 +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 j0LEjXHZ059575; Fri, 21 Jan 2005 15:45:33 +0100 (MET) (envelope-from j) Resent-Message-Id: <200501211445.j0LEjXHZ059575@uriah.heep.sax.de> Date: Fri, 21 Jan 2005 15:44:28 +0100 From: Joerg Wunsch To: current@freebsd.org Message-ID: <20050121144428.GK30862@uriah.heep.sax.de> References: <20050120223232.GF30862@uriah.heep.sax.de> <20050120224753.GB71573@nagual.pp.ru> <20050120192324.GA30862@uriah.heep.sax.de> <20050120205501.GA69123@nagual.pp.ru> <20050120211449.GC30862@uriah.heep.sax.de> <20050120214406.GA70088@nagual.pp.ru> <20050120222137.GE30862@uriah.heep.sax.de> <20050121000916.GA73235@nagual.pp.ru> <20050121125801.GA94152@nagual.pp.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050120222137.GE30862@uriah.heep.sax.de> <20050120224753.GB71573@nagual.pp.ru> <20050121125801.GA94152@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 Resent-From: j@uriah.heep.sax.de Resent-Date: Fri, 21 Jan 2005 15:45:33 +0100 Resent-To: current@freebsd.org, bde@freebsd.org, ache@nagual.pp.ru 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: Fri, 21 Jan 2005 14:50:11 -0000 As Joerg Wunsch wrote: > As a demonstration, consider this test program: ... > Below are the results for Solaris 8, FreeBSD 5, Linux 2.x, and HP-UX > 10.20. ... > It's quite obvious that any other system differs from FreeBSD here. > (OK, HP-UX doesn't throw EINVAL at all, even for clearly > inconvertible strings. But then, it's a pretty old system, more > than ten years.) Btw., I have re-checked HP-UX once more. They do set errno to EINVAL in the case of an unacceptable value for base, as required by Posix/SUSP. They only never set it to EINVAL for a conversion error. So they are *fully* compliant with Posix/SUSP. Hmm, maybe not. For "0x", they do not set endptr to point to the `x', so they're still in violation. Seems they are using the old BSD code which had the same bug. But that's another matter. Btw., Solaris never sets errno to EINVAL except for the unacceptable base case (where SUSP requires it). This is the best demonstration that the entire ``may set to EINVAL'' thing in SUSP is pointless crap, sorry. As no application developer can rely on it, they could as well have left this option completely out. If someone wants to use strot() to verify their input data, they'd be best to follow the advise from the FreeBSD manpage: ``(Thus, if *nptr is not `\0' but **endptr is `\0' on return, the entire string was valid.)'' This is the only reliable method. (OK, if you care, you can then check for errno being set to ERANGE in order to detect an under-/overflow situation.) As Andrey Chernov wrote: > This is just your speculation about what "expected form" is. But > POSIX clearly says, what expected form is: > "If the value of base is 0, the expected form of the subject > sequence is ^^^^^^^^^^^^^^^^^^^ that of a decimal constant, octal > constant, or hexadecimal constant, any of which may be preceded by a > .+. or .-. sign." > No CONSTANT found in just +- case. OK, I agree on this. I still find the wording of the standard ambiguous, as some forms of conversion errors (the empty string) are explicitly mentioned, while other forms (a single sign) have to be derived, but I agree. It of course makes most sense that way anyway, I've only been surprised about the mentioned ambiguity in the standard. > > Is not SUS v3 == "POSIX" 2001 edition (IEEE Std 1003.1-2001)? > Yes, with two technical corrigendum, as I read their announce. But > Joerg mention older SUSv2 and I mean it too. I didn't have SUSPv3 handy, so I referred to v2 (where I have been registering years ago). Thanks for the v3 pointer, that might be handy as well. The question about whether the C standard allows setting errno to EINVAL was merely out of curiosity. I still think that the C standard forbids it, but I do find that stupid as well, and never meant to change that part of the FreeBSD behaviour. I agree that fixing the 0x problem would fix the part were FreeBSD currently violates the standard. However, as the majority of other SUSP compliant systems seem to prefer to not set errno in the empty string case, I suggest we follow that instead of our current behaviour. Maybe we should even follow the Solaris behaviour, and not mess with EINVAL at all except where required by SUSP. See above, EINVAL is completely pointless for error checking as it is not portable. -- cheers, J"org .-.-. --... ...-- -.. . DL8DTL http://www.sax.de/~joerg/ NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)