From 7c2d72933f0d49aeac8e89082e833c41bda2b9f9 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 21 Jun 2023 14:52:44 +0000 Subject: (partial) fix for [https://core.tcl-lang.org/tk/tktview/a9929f112a|a9929f112a]. Tk needs some changes too --- generic/tclUtil.c | 5 ++++- tests/indexObj.test | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 30ae39a..074614f 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -3660,6 +3660,9 @@ GetWideForIndex( if (numType == TCL_NUMBER_INT) { /* objPtr holds an integer in the signed wide range */ *widePtr = *(Tcl_WideInt *)cd; + if ((*widePtr < 0)) { + *widePtr = WIDE_MIN; + } return TCL_OK; } if (numType == TCL_NUMBER_BIG) { @@ -3966,7 +3969,7 @@ GetEndOffsetFromObj( offset = irPtr->wideValue; if (offset == WIDE_MAX) { - *widePtr = endValue + 1; + *widePtr = (endValue == (size_t)-1) ? WIDE_MAX : endValue + 1; } else if (offset == WIDE_MIN) { *widePtr = -1; } else if (endValue == (size_t)-1) { diff --git a/tests/indexObj.test b/tests/indexObj.test index 2c50200..1cf782a 100644 --- a/tests/indexObj.test +++ b/tests/indexObj.test @@ -211,10 +211,16 @@ test indexObj-8.13 {Tcl_GetIntForIndex end} testgetintforindex { } -2 test indexObj-8.14 {Tcl_GetIntForIndex end+1} testgetintforindex { testgetintforindex end+1 -1 -} 0 +} 2147483647 test indexObj-8.15 {Tcl_GetIntForIndex end+1} testgetintforindex { testgetintforindex end+1 -2 } -1 +test indexObj-8.16 {Tcl_GetIntForIndex integer} testgetintforindex { + testgetintforindex -1 -1 +} -2147483648 +test indexObj-8.17 {Tcl_GetIntForIndex integer} testgetintforindex { + testgetintforindex -2 -1 +} -2147483648 # cleanup ::tcltest::cleanupTests -- cgit v0.12 From bc87d9a2bc25805bbeda05983b9a403d0767fb1f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 21 Jun 2023 21:30:53 +0000 Subject: Fix 3 "lset" testcases --- generic/tclListObj.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generic/tclListObj.c b/generic/tclListObj.c index d3e4f02..0fd489c 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -2871,6 +2871,9 @@ TclLsetFlat( } indexArray++; + if ((index == INT_MAX) && (elemCount == 0)) { + index = 0; + } if (index < 0 || index > elemCount || (valueObj == NULL && index >= elemCount)) { /* ...the index points outside the sublist. */ -- cgit v0.12