From 2eb24794969d407846d80bce8ca07c486fb4ab0b Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 19 Aug 2004 20:58:59 +0000 Subject: Ensure that the %ld conversion works correctly on 64-bit platforms. [Bug 1011860] --- ChangeLog | 5 +++++ generic/tclScan.c | 15 +++++---------- tests/scan.test | 7 +++++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ce9d62..8170a2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-08-19 Donal K. Fellows + + * generic/tclScan.c (Tcl_ScanObjCmd, ValidateFormat): Ensure that + the %ld conversion works correctly on 64-bit platforms. [Bug 1011860] + 2004-08-19 Kevin Kenny * library/clock.tcl (format): Changed default timezone format diff --git a/generic/tclScan.c b/generic/tclScan.c index 47d40bd..69e4170 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclScan.c,v 1.14 2004/05/27 13:18:53 dkf Exp $ + * RCS: @(#) $Id: tclScan.c,v 1.15 2004/08/19 20:59:00 dkf Exp $ */ #include "tclInt.h" @@ -367,9 +367,7 @@ ValidateFormat(interp, format, numVars, totalSubs) switch (ch) { case 'l': case 'L': -#ifndef TCL_WIDE_INT_IS_LONG flags |= SCAN_LONGER; -#endif case 'h': format += Tcl_UtfToUniChar(format, &ch); } @@ -700,9 +698,7 @@ Tcl_ScanObjCmd(dummy, interp, objc, objv) switch (ch) { case 'l': case 'L': -#ifndef TCL_WIDE_INT_IS_LONG flags |= SCAN_LONGER; -#endif /* * Fall through so we skip to the next character. */ @@ -1036,12 +1032,11 @@ Tcl_ScanObjCmd(dummy, interp, objc, objv) if ((flags & SCAN_UNSIGNED) && (value < 0)) { sprintf(buf, "%lu", value); /* INTL: ISO digit */ objPtr = Tcl_NewStringObj(buf, -1); + } else if ((flags & SCAN_LONGER) + || (unsigned long) value > UINT_MAX) { + objPtr = Tcl_NewLongObj(value); } else { - if ((unsigned long) value > UINT_MAX) { - objPtr = Tcl_NewLongObj(value); - } else { - objPtr = Tcl_NewIntObj(value); - } + objPtr = Tcl_NewIntObj(value); } #ifndef TCL_WIDE_INT_IS_LONG } diff --git a/tests/scan.test b/tests/scan.test index a86c3da..94ff998 100644 --- a/tests/scan.test +++ b/tests/scan.test @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: scan.test,v 1.14 2002/06/22 04:19:47 dgp Exp $ +# RCS: @(#) $Id: scan.test,v 1.15 2004/08/19 20:59:00 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -417,12 +417,15 @@ test scan-5.11 {integer scanning} {nonPortable} { list [scan "4294967280 4294967280" "%u %d" a b] $a \ [expr {$b == -16 || $b == 0x7fffffff}] } {2 4294967280 1} - test scan-5.12 {integer scanning} {64bitInts} { set a {}; set b {}; set c {} list [scan "7810179016327718216,6c63546f6c6c6548,661432506755433062510" \ %ld,%lx,%lo a b c] $a $b $c } {3 7810179016327718216 7810179016327718216 7810179016327718216} +test scan-5.13 {integer scanning and overflow} { + # This test used to fail on some 64-bit systems. [Bug 1011860] + scan {300000000 3000000000 30000000000} {%ld %ld %ld} +} {300000000 3000000000 30000000000} test scan-6.1 {floating-point scanning} { set a {}; set b {}; set c {}; set d {} -- cgit v0.12