From owner-freebsd-current@FreeBSD.ORG Thu Jan 20 20:39:53 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 0579F16A4CE for ; Thu, 20 Jan 2005 20:39:53 +0000 (GMT) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3944443D1D for ; Thu, 20 Jan 2005 20:39:52 +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 j0KKdpYu052710 for ; Thu, 20 Jan 2005 21:39:51 +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 j0KKdpk5052709 for current@freebsd.org; Thu, 20 Jan 2005 21:39:51 +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 j0KKcZv6033025 for ; Thu, 20 Jan 2005 21:38:35 +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 j0KKcZ9K033024 for current@freebsd.org; Thu, 20 Jan 2005 21:38:35 +0100 (MET) (envelope-from j) Resent-Message-Id: <200501202038.j0KKcZ9K033024@uriah.heep.sax.de> Date: Thu, 20 Jan 2005 20:23:24 +0100 From: Joerg Wunsch To: current@freebsd.org Message-ID: <20050120192324.GA30862@uriah.heep.sax.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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: Thu, 20 Jan 2005 21:38:34 +0100 Resent-To: current@freebsd.org 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: bde@freebsd.org Subject: 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 20:39:53 -0000 While analyzing an implementation of strtol() for the AVR microcontroller (as part of the opensource C library for it), I noticed a few violations of the C standard in FreeBSD's implementation. I didn't check, but I'd expect similar issues to apply to related functions. 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 not covered by the standard at all, of course this is debatable, but I clearly read the standard the way that "" or " " are not convertible, while "+" and "-" are. Second (and much more of an issue), sequences consisting solely of a "0x" (with any permutations of leading white space and/or sign) are *always* convertible, as the leading 0 is always a valid number, so conversion only has to stop at the "x". This is a clear bug in my opinion. Btw., what's the position of the C standard for errno values that are not covered by the C standard itself? I see SUSPv2 supports the notion of EINVAL, but it's not clear to me whether the C standard would allow non-standard extension for functions where the standard describes the possible errno changes. -- cheers, J"org .-.-. --... ...-- -.. . DL8DTL http://www.sax.de/~joerg/ NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)