From owner-freebsd-bugs@FreeBSD.ORG Tue Jun 23 03:20:05 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 345E71065672 for ; Tue, 23 Jun 2009 03:20:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 21EE58FC0A for ; Tue, 23 Jun 2009 03:20:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n5N3K4GQ073805 for ; Tue, 23 Jun 2009 03:20:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n5N3K4uL073804; Tue, 23 Jun 2009 03:20:04 GMT (envelope-from gnats) Date: Tue, 23 Jun 2009 03:20:04 GMT Message-Id: <200906230320.n5N3K4uL073804@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Evans Cc: Subject: Re: misc/135932: 'strtol' doesn't reset errno to 0 when converting MAX_INT=2147483647 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Bruce Evans List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2009 03:20:05 -0000 The following reply was made to PR misc/135932; it has been noted by GNATS. From: Bruce Evans To: Yuri Cc: freebsd-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org Subject: Re: misc/135932: 'strtol' doesn't reset errno to 0 when converting MAX_INT=2147483647 Date: Tue, 23 Jun 2009 12:02:12 +1000 (EST) On Mon, 22 Jun 2009, Yuri wrote: >> Description: > When strtol is supplied string 2147483647 it's impossible to distinguish between overflow and non-overflow situation since return value is the same one that flags overflow (MAX_INT) and strtol doesn't clear errno in this case. No, this is easy to distinguish: set errno to 0 (or just to some value different from ERANGE) before calling strtol(), and check errno after calling strtol(). The check can be omitted unless strtol() actually returns INT_MAX. The setting before the call can only be omitted it this error can't happen or if the caller doesn't check for it. Most uses of the strtol() family get this wrong by not even checking :-(. > strtol should set errno=0 in this case to avoid ambiguity. No, strtol() must not set errno to 0. The C standard doesn't permit any library function to set errno to 0. Bruce