Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Jan 2005 01:11:54 +0300
From:      Andrey Chernov <ache@nagual.pp.ru>
To:        Joerg Wunsch <joerg_wunsch@uriah.heep.sax.de>, current@FreeBSD.ORG, bde@FreeBSD.ORG
Subject:   [patch] Re: Implementation errors in strtol()
Message-ID:  <20050120221154.GC70629@nagual.pp.ru>
In-Reply-To: <20050120215807.GA70629@nagual.pp.ru>
References:  <20050120192324.GA30862@uriah.heep.sax.de> <20050120205501.GA69123@nagual.pp.ru> <20050120211449.GC30862@uriah.heep.sax.de> <20050120214406.GA70088@nagual.pp.ru> <20050120215807.GA70629@nagual.pp.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jan 21, 2005 at 12:58:07AM +0300, Andrey Chernov wrote:
> "If the value of base is 16, the characters 0x or 0X may optionally 
>                                                          ^^^^^^^^^^^
> precede the sequence of letters and digits, following the sign if 
> present."

Here is untested patch to fix the problem:

--- strtol.c.bak	Fri Jan 21 01:06:06 2005
+++ strtol.c	Fri Jan 21 01:09:30 2005
@@ -76,7 +76,11 @@
 			c = *s++;
 	}
 	if ((base == 0 || base == 16) &&
-	    c == '0' && (*s == 'x' || *s == 'X')) {
+	    c == '0' && (*s == 'x' || *s == 'X') &&
+	    (s[1] >= 'a' && s[1] <= 'f' ||
+	     s[1] >= 'A' && s[1] <= 'F' ||
+	     s[1] >= '0' && s[1] <= '9')
+	   ) {
 		c = s[1];
 		s += 2;
 		base = 16;

-- 
http://ache.pp.ru/



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