Tcl Source Code

Artifact [77e5f2878c]
Login

Artifact 77e5f2878c759a81e5db2f68a999753d5f6607df:

Attachment "strtoul.patch" to ticket [440916ffff] added by dgp 2001-07-13 12:28:14.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tcl/tcl/ChangeLog,v
retrieving revision 1.494
diff -u -r1.494 ChangeLog
--- ChangeLog	2001/07/12 13:36:09	1.494
+++ ChangeLog	2001/07/13 05:22:44
@@ -1,3 +1,8 @@
+2001-07-12  Don Porter  <[email protected]>
+
+	* compat/strtoul.c (strtoul): Fixed failure to handle leading
+	sign symbols '+' and '-' and leading "0X".  [Bug 440916]
+
 2001-07-12  Donal K. Fellows  <[email protected]>
 
 	* tests/unixInit.test (unixInit-2.8): Added extra constraint,
Index: compat/strtoul.c
===================================================================
RCS file: /cvsroot/tcl/tcl/compat/strtoul.c,v
retrieving revision 1.2
diff -u -r1.2 strtoul.c
--- compat/strtoul.c	1998/09/14 18:39:45	1.2
+++ compat/strtoul.c	2001/07/13 05:22:46
@@ -71,6 +71,7 @@
     register unsigned long int result = 0;
     register unsigned digit;
     int anyDigits = 0;
+    int negative=0;
 
     /*
      * Skip any leading blanks.
@@ -80,6 +81,14 @@
     while (isspace(*p)) {
 	p += 1;
     }
+    if (*p == '-') {
+        negative = 1;
+        p += 1;
+    } else {
+        if (*p == '+') {
+            p += 1;
+        }
+    }
 
     /*
      * If no base was provided, pick one from the leading characters
@@ -90,7 +99,7 @@
     {
 	if (*p == '0') {
 	    p += 1;
-	    if (*p == 'x') {
+	    if ((*p == 'x') || (*p == 'X')) {
 		p += 1;
 		base = 16;
 	    } else {
@@ -111,7 +120,7 @@
 	 * Skip a leading "0x" from hex numbers.
 	 */
 
-	if ((p[0] == '0') && (p[1] == 'x')) {
+	if ((p[0] == '0') && ((p[1] == 'x') || (p[1] == 'X'))) {
 	    p += 2;
 	}
     }
@@ -179,5 +188,8 @@
 	*endPtr = p;
     }
 
+    if (negative) {
+	return -result;
+    }
     return result;
 }