summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-08-13 11:56:12 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-08-13 11:56:12 (GMT)
commite2d5a2cd606bb2952ffe3c2f00fdcc0132b57130 (patch)
tree39da0c77e31060d81deb9f63f75cc5e0309855dd
parent5860a8926709c0d0c4fad457796af2b666a39ca1 (diff)
downloadtcl-e2d5a2cd606bb2952ffe3c2f00fdcc0132b57130.zip
tcl-e2d5a2cd606bb2952ffe3c2f00fdcc0132b57130.tar.gz
tcl-e2d5a2cd606bb2952ffe3c2f00fdcc0132b57130.tar.bz2
Merge in fix for end+1 indices.
-rw-r--r--generic/tclListObj.c8
-rw-r--r--generic/tclUtil.c9
2 files changed, 13 insertions, 4 deletions
diff --git a/generic/tclListObj.c b/generic/tclListObj.c
index dac75d4..fd69c96 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -2927,6 +2927,14 @@ TclLsetFlat(
}
indexArray++;
+ /*
+ * Special case 0-length lists. The Tcl indexing function treat
+ * will return any value beyond length as TCL_SIZE_MAX for this
+ * case.
+ */
+ if ((index == TCL_SIZE_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 ff212b0..858a490 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -3702,14 +3702,15 @@ GetEndOffsetFromObj(
if (offset == WIDE_MAX) {
/*
- * Encodes end+1. This is distinguished from end+n as noted above
+ * Encodes end+1. This is distinguished from end+n as noted
+ * in function header.
* NOTE: this may wrap around if the caller passes (as lset does)
* listLen-1 as endValue and and listLen is 0. The -1 will be
* interpreted as FF...FF and adding 1 will result in 0 which
- * is what we want. 2's complements shenanigans but it is what
- * it is ...
+ * is what we want. Callers like lset which pass in listLen-1 == -1
+ * as endValue will have to adjust accordingly.
*/
- *widePtr = endValue + 1;
+ *widePtr = (endValue == -1) ? WIDE_MAX : endValue + 1;
} else if (offset == WIDE_MIN) {
/* -1 - position before first */
*widePtr = -1;