From 17efc09f1ef6cf0d49925423ef414a55c83320b2 Mon Sep 17 00:00:00 2001 From: dkf Date: Fri, 17 Jun 2005 23:26:06 +0000 Subject: Fix bug in [format %hx] handling on selected platforms. [Bug 1154163] --- ChangeLog | 5 +++++ generic/tclCmdAH.c | 38 ++++++++++++++++++++++---------------- tests/format.test | 6 +++++- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index dec2092..f9e9186 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-06-18 Donal K. Fellows + + * generic/tclCmdAH.c (Tcl_FormatObjCmd): Fix for [Bug 1154163]; only + * tests/format.test: insert 'l' modifier when it is needed. + 2005-06-07 Donal K. Fellows * unix/tclUnixNotfy.c (Tcl_FinalizeNotifier): Add dummy variable diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 4d99fbd..9c9fe7e 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.27.2.11 2004/10/30 21:00:09 msofer Exp $ + * RCS: @(#) $Id: tclCmdAH.c,v 1.27.2.12 2005/06/17 23:26:20 dkf Exp $ */ #include "tclInt.h" @@ -2187,31 +2187,37 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv) case 'u': case 'x': case 'X': - if ( useWide ) { - if ( Tcl_GetWideIntFromObj( interp, /* INTL: Tcl source. */ - objv[objIndex], &wideValue ) - != TCL_OK ) { + if (useWide) { + if (Tcl_GetWideIntFromObj(interp, /* INTL: Tcl source. */ + objv[objIndex], &wideValue) != TCL_OK) { goto fmtError; } whichValue = WIDE_VALUE; size = 40 + precision; break; } - if ( Tcl_GetLongFromObj( interp, /* INTL: Tcl source. */ - objv[objIndex], &intValue ) != TCL_OK ) { + if (Tcl_GetLongFromObj(interp, /* INTL: Tcl source. */ + objv[objIndex], &intValue) != TCL_OK) { goto fmtError; } #if (LONG_MAX > INT_MAX) - /* - * Add the 'l' for long format type because we are on an - * LP64 archtecture and we are really going to pass a long - * argument to sprintf. - */ - newPtr++; - *newPtr = 0; - newPtr[-1] = newPtr[-2]; - newPtr[-2] = 'l'; + if (!useShort) { + /* + * Add the 'l' for long format type because we are on an + * LP64 archtecture and we are really going to pass a long + * argument to sprintf. + * + * Do not add this if we're going to pass in a short (i.e. + * if we've got an 'h' modifier already in the string); some + * libc implementations of sprintf() do not like it at all. + * [Bug 1154163] + */ + newPtr++; + *newPtr = 0; + newPtr[-1] = newPtr[-2]; + newPtr[-2] = 'l'; + } #endif /* LONG_MAX > INT_MAX */ whichValue = INT_VALUE; size = 40 + precision; diff --git a/tests/format.test b/tests/format.test index 3ca51ac..448f162 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.11.2.6 2004/10/27 17:55:14 kennykb Exp $ +# RCS: @(#) $Id: format.test,v 1.11.2.7 2005/06/17 23:26:20 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -365,6 +365,10 @@ test format-10.2 {"h" format specifier} {nonPortable} { test format-10.3 {"h" format specifier} {nonPortable} { format %hd 0x10000 } 0 +test format-10.4 {"h" format specifier} { + # Bug 1154163: This is minimal behaviour for %hx specifier! + format %hx 1 +} 1 test format-11.1 {XPG3 %$n specifiers} { format {%2$d %1$d} 4 5 -- cgit v0.12