summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclCmdAH.c17
-rw-r--r--tests/format.test25
3 files changed, 43 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 4621888..79ad729 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-05-14 Donal K. Fellows <fellowsd@cs.man.ac.uk>
+
+ * generic/tclCmdAH.c (Tcl_FormatObjCmd): Stop unwarranted demotion
+ of wide values to longs by formatting of int values. [Bug 699060]
+
2003-05-14 Jeff Hobbs <jeffh@ActiveState.com>
* library/encoding/gb2312.enc: copy euc-cn.enc over original
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 3731974..d4788be 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -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: tclCmdAH.c,v 1.32 2003/05/05 20:54:38 dgp Exp $
+ * RCS: @(#) $Id: tclCmdAH.c,v 1.33 2003/05/14 22:45:12 dkf Exp $
*/
#include "tclInt.h"
@@ -2256,7 +2256,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
case 'x':
case 'X':
if (useWide) {
- if (Tcl_GetWideIntFromObj(interp, /* INTL: Tcl source. */
+ if (Tcl_GetWideIntFromObj(interp, /* INTL: Tcl source. */
objv[objIndex], &wideValue) != TCL_OK) {
goto fmtError;
}
@@ -2264,7 +2264,18 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
size = 40 + precision;
break;
}
- if (Tcl_GetLongFromObj(interp, /* INTL: Tcl source. */
+ if (objv[objIndex]->typePtr == &tclWideIntType) {
+ /* Operation won't fail; we're typed! */
+ Tcl_GetWideIntFromObj(NULL, objv[objIndex], &wideValue);
+ if (wideValue>ULONG_MAX || wideValue<LONG_MIN) {
+ /*
+ * Value too big for type. Generate an error;
+ */
+ Tcl_GetLongFromObj(interp, objv[objIndex], &intValue);
+ goto fmtError;
+ }
+ intValue = Tcl_WideAsLong(wideValue);
+ } else if (Tcl_GetLongFromObj(interp, /* INTL: Tcl source. */
objv[objIndex], &intValue) != TCL_OK) {
goto fmtError;
}
diff --git a/tests/format.test b/tests/format.test
index 7c383ee..1e57bd4 100644
--- a/tests/format.test
+++ b/tests/format.test
@@ -10,7 +10,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: format.test,v 1.14 2003/03/27 13:19:15 dkf Exp $
+# RCS: @(#) $Id: format.test,v 1.15 2003/05/14 22:45:12 dkf Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
@@ -505,6 +505,29 @@ test format-17.4 {testing %l with non-integer} {
format %lf 1
} 1.000000
+test format-18.1 {do not demote existing numeric values} {
+ set a 0xaaaaaaaa
+ # Ensure $a and $b are separate objects
+ set b 0xaaaa
+ append b aaaa
+
+ set result [expr {$a == $b}]
+ format %08lx $b
+ lappend result [expr {$a == $b}]
+
+ set b 0xaaaa
+ append b aaaa
+
+ lappend result [expr {$a == $b}]
+ format %08x $b
+ lappend result [expr {$a == $b}]
+} {1 1 1 1}
+test format-18.2 {do not demote existing numeric values} {
+ set a [expr {0xaaaaaaaaaa + 1}]
+ set b 0xaaaaaaaaab
+ list [catch {format %08x $a} msg] $msg [expr {$a == $b}]
+} {1 {integer value too large to represent} 1}
+
# cleanup
catch {unset a}
catch {unset b}