summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2005-06-17 23:41:00 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2005-06-17 23:41:00 (GMT)
commit1eab272665547e3f9be60541313af2b3c614c747 (patch)
tree6c75fc7a238a9d2b00bfd317f1b847798a418e12
parente1e80d15370c158d3ae2870cfc5d26e1d9791046 (diff)
downloadtcl-1eab272665547e3f9be60541313af2b3c614c747.zip
tcl-1eab272665547e3f9be60541313af2b3c614c747.tar.gz
tcl-1eab272665547e3f9be60541313af2b3c614c747.tar.bz2
Fix bug in [format %hx] handling on selected platforms. [Bug 1154163]
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclCmdAH.c27
-rw-r--r--tests/format.test6
3 files changed, 27 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 0de5f2b..04993da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-06-18 Donal K. Fellows <donal.k.fellows@man.ac.uk>
+
+ * generic/tclCmdAH.c (Tcl_FormatObjCmd): Fix for [Bug 1154163]; only
+ * tests/format.test: insert 'l' modifier when it is needed.
+
2005-06-17 Donal K. Fellows <dkf@users.sf.net>
* generic/tclTimer.c (AfterDelay): Split out the code to manage
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 14b5e66..c2fae75 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.62 2005/06/07 09:04:00 dkf Exp $
+ * RCS: @(#) $Id: tclCmdAH.c,v 1.63 2005/06/17 23:41:03 dkf Exp $
*/
#include "tclInt.h"
@@ -2221,15 +2221,22 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv)
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 653ec35..afb18b0 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.19 2004/10/27 17:56:22 kennykb Exp $
+# RCS: @(#) $Id: format.test,v 1.20 2005/06/17 23:41:03 dkf Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
@@ -364,6 +364,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