From owner-freebsd-current@FreeBSD.ORG Fri Jan 21 23:10:23 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 2CABA16A4D1; Fri, 21 Jan 2005 23:10:23 +0000 (GMT) Received: from VARK.MIT.EDU (VARK.MIT.EDU [18.95.3.179]) by mx1.FreeBSD.org (Postfix) with ESMTP id 908E043D4C; Fri, 21 Jan 2005 23:10:14 +0000 (GMT) (envelope-from das@FreeBSD.ORG) Received: from VARK.MIT.EDU (localhost [127.0.0.1]) by VARK.MIT.EDU (8.13.1/8.13.1) with ESMTP id j0LN9oaR034541; Fri, 21 Jan 2005 18:09:50 -0500 (EST) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.MIT.EDU (8.13.1/8.13.1/Submit) id j0LN9nKe034540; Fri, 21 Jan 2005 18:09:49 -0500 (EST) (envelope-from das@FreeBSD.ORG) Date: Fri, 21 Jan 2005 18:09:49 -0500 From: David Schultz To: Joerg Wunsch Message-ID: <20050121230949.GA34313@VARK.MIT.EDU> Mail-Followup-To: Joerg Wunsch , current@freebsd.org, Andrey Chernov , bde@freebsd.org References: <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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050120222137.GE30862@uriah.heep.sax.de> cc: Andrey Chernov cc: current@FreeBSD.ORG cc: bde@FreeBSD.ORG Subject: Re: Implementation errors in strtol() X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list 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 23:10:23 -0000 Regarding the interpretation of sequences such as "0x" and "+": These are disallowed by the BNF in section 6.4.4.1 of the C99 standard. The specification of strtol() says: 7.20.1.4.3 If the value of base is zero, the expected form of the subject sequence is that of an integer constant as described in 6.4.4.1 [...] If the value of base is between 2 and 36 (inclusive), the expected form of the subject sequence is a sequence of letters and digits representing an integer 7.20.1.4.7 If the subject sequence is empty or does not have the expected form, no conversion is performed; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a null pointer. The specification of the base != 0 case is less precise, but it is logical to assume that the authors intended it to be the similar in spirit to the base == 0 case, particularly wrt invalid sequences such as "+". Regarding the use of errno: The ISO C standard allows any library function to set errno to EFOO unless it explicitly says EFOO is used to mean something else for that function. So setting errno to EINVAL in strtol() is allowed by the C standard. POSIX says strtol() may set errno to EINVAL if no conversion is performed, and this is explicitly annotated as an extension to the C standard. However, the implementation is also free to *not* set errno in this case. Therefore, the errno issue is more about pragmatics than standards-compliance. I think the two important questions are: o Is there lots of broken software out there that expects errno to not be set? o Is there FreeBSD software out there that would break if we broke POLA and stopped setting errno?