summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclListObj.c3
-rw-r--r--generic/tclUtil.c5
-rw-r--r--tests/indexObj.test8
3 files changed, 14 insertions, 2 deletions
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. */
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