From bde854f794edc2436b9676018f5a4352cc679e3c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 16 Nov 2023 19:26:36 +0000 Subject: Fix binary/format/string testcase failures on 32-bit platforms. Reported by Harald Oehlmann. --- generic/tclBinary.c | 4 ++-- generic/tclCmdMZ.c | 17 +++++++++++++---- generic/tclStringObj.c | 20 +++++++++----------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/generic/tclBinary.c b/generic/tclBinary.c index f14685a..545ff7d 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -2609,7 +2609,7 @@ BinaryEncode64( { Tcl_Obj *resultObj; unsigned char *data, *limit; - Tcl_Size maxlen = 0; + Tcl_WideInt maxlen = 0; const char *wrapchar = "\n"; Tcl_Size wrapcharlen = 1; int index, purewrap = 1; @@ -2629,7 +2629,7 @@ BinaryEncode64( } switch (index) { case OPT_MAXLEN: - if (TclGetSizeIntFromObj(interp, objv[i + 1], &maxlen) != TCL_OK) { + if (Tcl_GetWideIntFromObj(interp, objv[i + 1], &maxlen) != TCL_OK) { return TCL_ERROR; } if (maxlen < 0) { diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index eecf675..7231548 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -2642,7 +2642,8 @@ StringEqualCmd( const char *string2; int i, match, nocase = 0; - Tcl_Size length, reqlength = -1; + Tcl_Size length; + Tcl_WideInt reqlength = -1; if (objc < 3 || objc > 6) { str_cmp_args: @@ -2661,9 +2662,12 @@ StringEqualCmd( goto str_cmp_args; } i++; - if (TclGetSizeIntFromObj(interp, objv[i], &reqlength) != TCL_OK) { + if (Tcl_GetWideIntFromObj(interp, objv[i], &reqlength) != TCL_OK) { return TCL_ERROR; } + if ((Tcl_WideUInt)reqlength > TCL_SIZE_MAX) { + reqlength = -1; + } } else { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad option \"%s\": must be -nocase or -length", @@ -2741,8 +2745,8 @@ StringCmpOpts( int i; Tcl_Size length; const char *string; + Tcl_WideInt wreqlength = -1; - *reqlength = -1; *nocase = 0; if (objc < 3 || objc > 6) { str_cmp_args: @@ -2761,9 +2765,14 @@ StringCmpOpts( goto str_cmp_args; } i++; - if (TclGetSizeIntFromObj(interp, objv[i], reqlength) != TCL_OK) { + if (Tcl_GetWideIntFromObj(interp, objv[i], &wreqlength) != TCL_OK) { return TCL_ERROR; } + if ((Tcl_WideUInt)wreqlength > TCL_SIZE_MAX) { + *reqlength = -1; + } else { + *reqlength = wreqlength; + } } else { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "bad option \"%s\": must be -nocase or -length", diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 598a2e5..8c78f2b 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -1848,7 +1848,7 @@ Tcl_AppendFormatToObj( char *end; int gotMinus = 0, gotHash = 0, gotZero = 0, gotSpace = 0, gotPlus = 0; int gotPrecision, sawFlag, useShort = 0, useBig = 0; - Tcl_Size width, precision; + Tcl_WideInt width, precision; #ifndef TCL_WIDE_INT_IS_LONG int useWide = 0; #endif @@ -1964,12 +1964,12 @@ Tcl_AppendFormatToObj( unsigned long long ull; ull = strtoull(format, &end, 10); /* Comparison is >=, not >, to leave room for nul */ - if (ull >= TCL_SIZE_MAX) { + if (ull >= WIDE_MAX) { msg = overflow; errCode = "OVERFLOW"; goto errorMsg; } - width = (Tcl_Size)ull; + width = (Tcl_WideInt)ull; format = end; step = TclUtfToUniChar(format, &ch); } else if (ch == '*') { @@ -1978,7 +1978,7 @@ Tcl_AppendFormatToObj( errCode = gotXpg ? "INDEXRANGE" : "FIELDVARMISMATCH"; goto errorMsg; } - if (TclGetSizeIntFromObj(interp, objv[objIndex], &width) != TCL_OK) { + if (TclGetWideIntFromObj(interp, objv[objIndex], &width) != TCL_OK) { goto error; } if (width < 0) { @@ -2010,12 +2010,12 @@ Tcl_AppendFormatToObj( unsigned long long ull; ull = strtoull(format, &end, 10); /* Comparison is >=, not >, to leave room for nul */ - if (ull >= TCL_SIZE_MAX) { + if (ull >= WIDE_MAX) { msg = overflow; errCode = "OVERFLOW"; goto errorMsg; } - precision = (Tcl_Size)ull; + precision = (Tcl_WideInt)ull; format = end; step = TclUtfToUniChar(format, &ch); } else if (ch == '*') { @@ -2024,7 +2024,7 @@ Tcl_AppendFormatToObj( errCode = gotXpg ? "INDEXRANGE" : "FIELDVARMISMATCH"; goto errorMsg; } - if (TclGetSizeIntFromObj(interp, objv[objIndex], &precision) + if (TclGetWideIntFromObj(interp, objv[objIndex], &precision) != TCL_OK) { goto error; } @@ -2471,16 +2471,14 @@ Tcl_AppendFormatToObj( *p++ = '+'; } if (width) { - p += snprintf( - p, TCL_INTEGER_SPACE, "%" TCL_SIZE_MODIFIER "d", width); + p += snprintf(p, TCL_INTEGER_SPACE, "%" TCL_LL_MODIFIER "d", width); if (width > length) { length = width; } } if (gotPrecision) { *p++ = '.'; - p += snprintf( - p, TCL_INTEGER_SPACE, "%" TCL_SIZE_MODIFIER "d", precision); + p += snprintf(p, TCL_INTEGER_SPACE, "%" TCL_LL_MODIFIER "d", precision); if (precision > TCL_SIZE_MAX - length) { msg = overflow; errCode = "OVERFLOW"; -- cgit v0.12