Tcl Source Code

Artifact [f19faaf427]
Login

Artifact f19faaf4276199a05cce326e540c50a599a59a22:

Attachment "495213.patch" to ticket [495213ffff] added by hobbs 2002-02-07 08:44:44.
Index: generic/tclScan.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclScan.c,v
retrieving revision 1.8
diff -b -u -r1.8 tclScan.c
--- generic/tclScan.c	2001/09/20 01:03:08	1.8
+++ generic/tclScan.c	2002/02/07 01:42:14
@@ -855,10 +855,17 @@
 			 * a number.  If we are unsure of the base, it
 			 * indicates that we are in base 8 or base 16 (if it is
 			 * followed by an 'x').
+			 *
+			 * 8.1 - 8.3.4 incorrectly handled 0x... base-16
+			 * cases for %x by not reading the 0x as the
+			 * auto-prelude for base-16. [Bug #495213]
 			 */
 			case '0':
 			    if (base == 0) {
 				base = 8;
+				flags |= SCAN_XOK;
+			    }
+			    if (base == 16) {
 				flags |= SCAN_XOK;
 			    }
 			    if (flags & SCAN_NOZERO) {
Index: tests/scan.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/scan.test,v
retrieving revision 1.11
diff -b -u -r1.11 scan.test
--- tests/scan.test	2000/12/10 03:27:04	1.11
+++ tests/scan.test	2002/02/07 01:42:14
@@ -231,9 +231,20 @@
     list [scan {+1238 -123a 0123} {%x%x%x} x y z] $x $y $z
 } {3 4664 -4666 291}
 test scan-4.40 {Tcl_ScanObjCmd, base-16 integer scanning} {
+    # The behavior changed in 8.4a4/8.3.4cvs (6 Feb) to correctly
+    # return '1' for 0x1 scanned via %x, to comply with 8.0 and C scanf.
+    # Bug #495213
     set x {}
     list [scan {aBcDeF AbCdEf 0x1} {%x%x%x} x y z] $x $y $z
-} {3 11259375 11259375 0}
+} {3 11259375 11259375 1}
+test scan-4.40.1 {Tcl_ScanObjCmd, base-16 integer scanning} {
+    set x {}
+    list [scan {0xF 0x00A0B 0X0XF} {%x %x %x} x y z] $x $y $z
+} {3 15 2571 0}
+test scan-4.40.2 {Tcl_ScanObjCmd, base-16 integer scanning} {
+    catch {unset x}
+    list [scan {xF} {%x} x] [info exists x]
+} {0 0}
 test scan-4.41 {Tcl_ScanObjCmd, base-unknown integer scanning} {
     set x {}
     list [scan {10 010 0x10} {%i%i%i} x y z] $x $y $z