[patch] Re: Implementation errors in strtol()

From: Andrey Chernov <ache_at_nagual.pp.ru>
Date: Fri, 21 Jan 2005 01:11:54 +0300
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
_at__at_ -76,7 +76,11 _at__at_
 			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/
Received on Thu Jan 20 2005 - 21:11:56 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:26 UTC