Tcl Source Code

Artifact [13a72a111e]
Login

Artifact 13a72a111ee17d64b5c11183ce42af4fd44d0503:

Attachment "alternative.patch" to ticket [1805896fff] added by dgp 2007-10-17 23:48:13.
Index: generic/tclStrToD.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclStrToD.c,v
retrieving revision 1.30
diff -u -r1.30 tclStrToD.c
--- generic/tclStrToD.c	23 Apr 2007 17:34:07 -0000	1.30
+++ generic/tclStrToD.c	17 Oct 2007 16:42:39 -0000
@@ -33,7 +33,7 @@
  * as octal. (Ceterum censeo: numeros octonarios delendos esse.)
  */
 
-#undef	KILL_OCTAL
+#define	KILL_OCTAL
 
 /*
  * This code supports (at least hypothetically), IBM, Cray, VAX and IEEE-754
@@ -302,6 +302,7 @@
 				 * to avoid a compiler warning. */
     int shift = 0;		/* Amount to shift when accumulating binary */
     int explicitOctal = 0;
+    int rejectLeadingZero = 0;
 
 #define ALL_BITS	(~(Tcl_WideUInt)0)
 #define MOST_BITS	(ALL_BITS >> 1)
@@ -413,6 +414,7 @@
 		break;
 	    }
 #ifdef KILL_OCTAL
+	    rejectLeadingZero = 1;
 	    goto decimal;
 #endif
 	    /* FALLTHROUGH */
@@ -636,9 +638,11 @@
 #ifdef KILL_OCTAL
 	decimal:
 #endif
-	    acceptState = state;
-	    acceptPoint = p;
-	    acceptLen = len;
+	    if (!rejectLeadingZero) {
+		acceptState = state;
+		acceptPoint = p;
+		acceptLen = len;
+	    }
 	    if (c == '0') {
 		++numTrailZeros;
 		state = DECIMAL;
@@ -658,9 +662,11 @@
 		goto endgame;
 	    } else if (c == '.') {
 		state = FRACTION;
+		rejectLeadingZero = 0;
 		break;
 	    } else if (c == 'E' || c == 'e') {
 		state = EXPONENT_START;
+		rejectLeadingZero = 0;
 		break;
 	    }
 	    goto endgame;