summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-12-16 10:09:40 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-12-16 10:09:40 (GMT)
commit3a7b07be0d7da9b0c0b0397913d4cce60c8160a5 (patch)
tree2ccd885e14228ae03d4269f3889c26366e058377
parentdbd3d4eff073d7b97d82ad5927cb6d60542f8541 (diff)
downloadtcl-3a7b07be0d7da9b0c0b0397913d4cce60c8160a5.zip
tcl-3a7b07be0d7da9b0c0b0397913d4cce60c8160a5.tar.gz
tcl-3a7b07be0d7da9b0c0b0397913d4cce60c8160a5.tar.bz2
Better fix for [3390638]: making the intVal variable unsigned prevents the need for using sprintf() altogether.
-rw-r--r--generic/tclUtil.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index d065069..f858bb4 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -3316,10 +3316,10 @@ TclFormatInt(buffer, n)
* formatted characters are written. */
long n; /* The integer to format. */
{
- long intVal;
+ unsigned long intVal;
int i;
int numFormatted, j;
- char *digits = "0123456789";
+ static const char digits[] = "0123456789";
/*
* Check first whether "n" is zero.
@@ -3332,27 +3332,16 @@ TclFormatInt(buffer, n)
}
/*
- * Check whether "n" is the maximum negative value. This is
- * -2^(m-1) for an m-bit word, and has no positive equivalent;
- * negating it produces the same value.
- */
-
- intVal = -n; /* [Bug 3390638] Workaround for*/
- if (n == -n || intVal == n) { /* broken compiler optimizers. */
- return sprintf(buffer, "%ld", n);
- }
-
- /*
* Generate the characters of the result backwards in the buffer.
*/
- intVal = (n < 0? -n : n);
+ intVal = (n < 0 ? -n : n);
i = 0;
buffer[0] = '\0';
do {
i++;
buffer[i] = digits[intVal % 10];
- intVal = intVal/10;
+ intVal = intVal / 10;
} while (intVal > 0);
if (n < 0) {
i++;