From owner-freebsd-bugs@FreeBSD.ORG Thu May 7 04:35:47 2009 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D8378106564A; Thu, 7 May 2009 04:35:47 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from fallbackmx06.syd.optusnet.com.au (fallbackmx06.syd.optusnet.com.au [211.29.132.8]) by mx1.freebsd.org (Postfix) with ESMTP id D36248FC17; Thu, 7 May 2009 04:35:46 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail02.syd.optusnet.com.au (mail02.syd.optusnet.com.au [211.29.132.183]) by fallbackmx06.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id n471k8q6009406; Thu, 7 May 2009 11:46:08 +1000 Received: from c122-106-172-38.carlnfd1.nsw.optusnet.com.au (c122-106-172-38.carlnfd1.nsw.optusnet.com.au [122.106.172.38]) by mail02.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id n471k2Nf006714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 7 May 2009 11:46:04 +1000 Date: Thu, 7 May 2009 11:46:02 +1000 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Yuri In-Reply-To: <200905062325.n46NPlSc079024@www.freebsd.org> Message-ID: <20090507113235.G9000@delplex.bde.org> References: <200905062325.n46NPlSc079024@www.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-bugs@freebsd.org, freebsd-gnats-submit@freebsd.org 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 List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 May 2009 04:35:48 -0000 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