From 449998d3589b262b87b42a2ad586dd3c70b4b9e2 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 19 Mar 2023 13:23:03 +0000 Subject: Proposed fix for [5ae5ffc3f4]: Problem with -failindex on 32-bit platform. This also fixes a memory-leak. --- generic/tclCmdAH.c | 17 +++++++++++------ generic/tclInt.h | 9 ++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 7fab2f0..dff231d 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -13,6 +13,7 @@ #include "tclInt.h" #include "tclIO.h" +#include "tclTomMath.h" #ifdef _WIN32 # include "tclWinInt.h" #endif @@ -580,13 +581,15 @@ EncodingConvertfromObjCmd( * data as was converted. */ if (failVarObj) { - /* I hope, wide int will cover Tcl_Size data type */ + Tcl_Obj *failIndex; + TclNewIndexObj(failIndex, errorLocation); if (Tcl_ObjSetVar2(interp, failVarObj, NULL, - Tcl_NewWideIntObj(errorLocation), + failIndex, TCL_LEAVE_ERR_MSG) == NULL) { - Tcl_DStringFree(&ds); + Tcl_DecrRefCount(failIndex); + Tcl_DStringFree(&ds); return TCL_ERROR; } } @@ -676,13 +679,15 @@ EncodingConverttoObjCmd( * data as was converted. */ if (failVarObj) { - /* I hope, wide int will cover Tcl_Size data type */ + Tcl_Obj *failIndex; + TclNewIndexObj(failIndex, errorLocation); if (Tcl_ObjSetVar2(interp, failVarObj, NULL, - Tcl_NewWideIntObj(errorLocation), + failIndex, TCL_LEAVE_ERR_MSG) == NULL) { - Tcl_DStringFree(&ds); + Tcl_DecrRefCount(failIndex); + Tcl_DStringFree(&ds); return TCL_ERROR; } } diff --git a/generic/tclInt.h b/generic/tclInt.h index a90ac79..aa9247f 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4912,7 +4912,14 @@ MODULE_SCOPE Tcl_LibraryInitProc Procbodytest_SafeInit; } while (0) #define TclNewIndexObj(objPtr, w) \ - (objPtr) = (((Tcl_WideUInt)w) >= TCL_INDEX_NONE) ? Tcl_NewWideIntObj(-1) : Tcl_NewWideIntObj(w) + do { + Tcl_WideUInt _uw = (Tcl_WideUInt)w; + if (_uw >= TCL_INDEX_NONE) { + TclNewIntObj(objPtr, -1); + } else { + TclNewUIntObj(objPtr, w); + } + } while (0) #define TclNewDoubleObj(objPtr, d) \ (objPtr) = Tcl_NewDoubleObj(d) -- cgit v0.12