From owner-freebsd-bugs@FreeBSD.ORG Thu May 7 04:40:02 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 EC35F106566C for ; Thu, 7 May 2009 04:40:02 +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 DAF3B8FC08 for ; Thu, 7 May 2009 04:40:02 +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 n474e2OX075005 for ; Thu, 7 May 2009 04:40:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n474e21G075004; Thu, 7 May 2009 04:40:02 GMT (envelope-from gnats) Date: Thu, 7 May 2009 04:40:02 GMT Message-Id: <200905070440.n474e21G075004@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Evans Cc: Subject: Re: misc/134320: strtol: overflow error when it shouldn't be 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: Thu, 07 May 2009 04:40:03 -0000 The following reply was made to PR misc/134320; it has been noted by GNATS. From: Bruce Evans To: Yuri Cc: freebsd-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org Subject: Re: misc/134320: strtol: overflow error when it shouldn't be Date: Thu, 7 May 2009 11:46:02 +1000 (EST) On Wed, 6 May 2009, Yuri wrote: > main() { > const char *nptr = "d223d221"; > long l = ::strtol(nptr, NULL, 16); > printf("l=%x errno=%i err=%s\n", l, errno, strerror(errno)); > } > ------------------------ > > It prints: l=7fffffff errno=34 err=Result too large > > Why result is too large? 0xd223d221 is a valid representation of a signed 32-bit integer between LONG_MIN=-2,147,483,648(0x80000000) and LONG_MAX=+2,147,483,647(0x7fffffff). Hex values are non-negative, so they can never give a valid representation of a negative integer. Here 0xd223d221 is an integer exceeding LONG_MAX. Bruce