Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 May 2009 04:40:02 GMT
From:      Bruce Evans <brde@optusnet.com.au>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: misc/134320: strtol: overflow error when it shouldn't be
Message-ID:  <200905070440.n474e21G075004@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/134320; it has been noted by GNATS.

From: Bruce Evans <brde@optusnet.com.au>
To: Yuri <yuri@tsoft.com>
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905070440.n474e21G075004>