summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclInt.h10
-rw-r--r--generic/tclUtil.c23
2 files changed, 22 insertions, 11 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index e9de2c3..003a360 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -4903,10 +4903,18 @@ MODULE_SCOPE Tcl_PackageInitProc Procbodytest_SafeInit;
} while (0)
#endif /* TCL_MEM_DEBUG */
+/*
+ * Macros to convert size_t to wide-int (and wide-int object) considering
+ * platform-related negative value ((size_t)-1), if wide-int and size_t
+ * have different dimensions (e. g. 32-bit platform).
+ */
+
#if (!defined(TCL_WIDE_INT_IS_LONG) || (LONG_MAX > UINT_MAX)) && (SIZE_MAX <= UINT_MAX)
+# define TclWideIntFromSize(value) (((Tcl_WideInt)(((size_t)(value))+1))-1)
# define TclNewWideIntObjFromSize(value) \
- Tcl_NewWideIntObj(((Tcl_WideInt)(((size_t)(value))+1))-1)
+ Tcl_NewWideIntObj(TclWideIntFromSize(value))
#else
+# define TclWideIntFromSize(value) (value)
# define TclNewWideIntObjFromSize Tcl_NewWideIntObj
#endif
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 24f5206..6f2fba5 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -3426,11 +3426,11 @@ TclFormatInt(
static int
GetWideForIndex(
Tcl_Interp *interp, /* Interpreter to use for error reporting. If
- * NULL, then no error message is left after
- * errors. */
+ * NULL, then no error message is left after
+ * errors. */
Tcl_Obj *objPtr, /* Points to the value to be parsed */
- Tcl_WideInt endValue, /* The value to be stored at *widePtr if
- * objPtr holds "end".
+ Tcl_WideInt endValue, /* The value to be stored at *widePtr if
+ * objPtr holds "end".
* NOTE: this value may be negative. */
Tcl_WideInt *widePtr) /* Location filled in with a wide integer
* representing an index. */
@@ -3639,7 +3639,10 @@ TclGetIntForIndex(
{
Tcl_WideInt wide;
- if (GetWideForIndex(interp, objPtr, endValue, &wide) == TCL_ERROR) {
+ /* Use platform-related size_t to wide-int to consider negative value
+ * ((size_t)-1) if wide-int and size_t have different dimensions. */
+ if (GetWideForIndex(interp, objPtr, TclWideIntFromSize(endValue),
+ &wide) == TCL_ERROR) {
return TCL_ERROR;
}
if (wide < INT_MIN) {
@@ -3670,11 +3673,11 @@ TclGetIntForIndex(
static int
GetEndOffsetFromObj(
- Tcl_Obj *objPtr, /* Pointer to the object to parse */
- Tcl_WideInt endValue, /* The value to be stored at "indexPtr" if
- * "objPtr" holds "end". */
- Tcl_WideInt *widePtr) /* Location filled in with an integer
- * representing an index. */
+ Tcl_Obj *objPtr, /* Pointer to the object to parse */
+ Tcl_WideInt endValue, /* The value to be stored at "indexPtr" if
+ * "objPtr" holds "end". */
+ Tcl_WideInt *widePtr) /* Location filled in with an integer
+ * representing an index. */
{
Tcl_ObjIntRep *irPtr;
Tcl_WideInt offset = 0; /* Offset in the "end-offset" expression */