Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 May 2009 23:25:47 GMT
From:      Yuri <yuri@tsoft.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/134320: strtol: overflow error when it shouldn't be
Message-ID:  <200905062325.n46NPlSc079024@www.freebsd.org>
Resent-Message-ID: <200905062330.n46NU5Cd057093@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         134320
>Category:       misc
>Synopsis:       strtol: overflow error when it shouldn't be
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 06 23:30:04 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Yuri
>Release:        7.2-PRERELEASE
>Organization:
n/a
>Environment:
>Description:
I look at the testcase:
---------------------------------
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

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).

So strtol could convert the value but didn't.

>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:
>Unformatted:



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