diff options
author | hobbs <hobbs> | 2001-09-20 01:03:08 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2001-09-20 01:03:08 (GMT) |
commit | 32d25a83797b68399f879b2bbdc6555c639487eb (patch) | |
tree | 3d9d23e524722e06cf15681524b4db6900855fa4 | |
parent | 43ce4a3c4a76eeb1a99a53e43ec6d32433e77680 (diff) | |
download | tcl-32d25a83797b68399f879b2bbdc6555c639487eb.zip tcl-32d25a83797b68399f879b2bbdc6555c639487eb.tar.gz tcl-32d25a83797b68399f879b2bbdc6555c639487eb.tar.bz2 |
* generic/tclCmdAH.c (Tcl_FormatObjCmd):
* generic/tclScan.c (Tcl_ScanObjCmd): corrected handling of format
and scan on 64-bit machines. [Bug #412696] (rmax)
-rw-r--r-- | generic/tclCmdAH.c | 19 | ||||
-rw-r--r-- | generic/tclScan.c | 17 |
2 files changed, 25 insertions, 11 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 3ea9aad..1645ad3 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.15 2001/09/04 18:06:34 vincentdarley Exp $ + * RCS: @(#) $Id: tclCmdAH.c,v 1.16 2001/09/20 01:03:08 hobbs Exp $ */ #include "tclInt.h" @@ -1854,7 +1854,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv) int size; /* Number of bytes needed for result of * conversion, based on type of conversion * ("e", "s", etc.), width, and precision. */ - int intValue; /* Used to hold value to pass to sprintf, if + long intValue; /* Used to hold value to pass to sprintf, if * it's a one-word integer or char value */ char *ptrValue = NULL; /* Used to hold value to pass to sprintf, if * it's a one-word value. */ @@ -1870,7 +1870,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv) # define DOUBLE_VALUE 3 # define STRING_VALUE 4 # define MAX_FLOAT_SIZE 320 - + Tcl_Obj *resultPtr; /* Where result is stored finally. */ char staticBuf[MAX_FLOAT_SIZE + 1]; /* A static buffer to copy the format results @@ -2090,10 +2090,19 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv) case 'u': case 'x': case 'X': - if (Tcl_GetIntFromObj(interp, /* INTL: Tcl source. */ + if (Tcl_GetLongFromObj(interp, /* INTL: Tcl source. */ objv[objIndex], &intValue) != TCL_OK) { goto fmtError; } + if ((unsigned long) intValue > UINT_MAX) { + /* + * Add the 'l' for long format type. + */ + newPtr++; + *newPtr = 0; + newPtr[-1] = newPtr[-2]; + newPtr[-2] = 'l'; + } whichValue = INT_VALUE; size = 40 + precision; break; @@ -2117,7 +2126,7 @@ Tcl_FormatObjCmd(dummy, interp, objc, objv) } break; case 'c': - if (Tcl_GetIntFromObj(interp, /* INTL: Tcl source. */ + if (Tcl_GetLongFromObj(interp, /* INTL: Tcl source. */ objv[objIndex], &intValue) != TCL_OK) { goto fmtError; } diff --git a/generic/tclScan.c b/generic/tclScan.c index 2cd48d4..23483e7 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.7 2000/12/10 03:27:04 hobbs Exp $ + * RCS: @(#) $Id: tclScan.c,v 1.8 2001/09/20 01:03:08 hobbs Exp $ */ #include "tclInt.h" @@ -539,7 +539,8 @@ Tcl_ScanObjCmd(dummy, interp, objc, objv) { char *format; int numVars, nconversions, totalVars = -1; - int objIndex, offset, i, value, result, code; + int objIndex, offset, i, result, code; + long value; char *string, *end, *baseString; char op = 0; int base = 0; @@ -644,7 +645,7 @@ Tcl_ScanObjCmd(dummy, interp, objc, objv) if (*end == '$') { format = end+1; format += Tcl_UtfToUniChar(format, &ch); - objIndex = value - 1; + objIndex = (int) value - 1; } } @@ -954,12 +955,16 @@ Tcl_ScanObjCmd(dummy, interp, objc, objv) if (!(flags & SCAN_SUPPRESS)) { *end = '\0'; - value = (int) (*fn)(buf, NULL, base); + value = (long) (*fn)(buf, NULL, base); if ((flags & SCAN_UNSIGNED) && (value < 0)) { - sprintf(buf, "%u", value); /* INTL: ISO digit */ + sprintf(buf, "%lu", value); /* INTL: ISO digit */ objPtr = Tcl_NewStringObj(buf, -1); } else { - objPtr = Tcl_NewIntObj(value); + if ((unsigned long) value > UINT_MAX) { + objPtr = Tcl_NewLongObj(value); + } else { + objPtr = Tcl_NewIntObj(value); + } } Tcl_IncrRefCount(objPtr); objs[objIndex++] = objPtr; |