summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraspect <aspect+tclcore@abstracted-spleen.org>2015-02-19 02:34:43 (GMT)
committeraspect <aspect+tclcore@abstracted-spleen.org>2015-02-19 02:34:43 (GMT)
commit48650316e3373be33455bab6db0a33546169c906 (patch)
tree437c7f1136cd39ced0be486e6e9ada7d6ee63f26
parent3f9555d4c2af861ded30792fc8a9c35b23187a2c (diff)
downloadtcl-48650316e3373be33455bab6db0a33546169c906.zip
tcl-48650316e3373be33455bab6db0a33546169c906.tar.gz
tcl-48650316e3373be33455bab6db0a33546169c906.tar.bz2
(core ticket [32b6159246]) Fix for [lreplace l x y] where y<x-1
-rw-r--r--generic/tclCompCmdsGR.c5
-rw-r--r--tests/lreplace.test6
2 files changed, 10 insertions, 1 deletions
diff --git a/generic/tclCompCmdsGR.c b/generic/tclCompCmdsGR.c
index e2fb43d..5220576 100644
--- a/generic/tclCompCmdsGR.c
+++ b/generic/tclCompCmdsGR.c
@@ -1524,6 +1524,9 @@ TclCompileLreplaceCmd(
tmpObj = Tcl_NewIntObj(idx1);
Tcl_IncrRefCount(tmpObj);
}
+ if(idx2 < idx1) {
+ idx2 = idx1-1;
+ }
goto dropRange;
}
}
@@ -1547,7 +1550,7 @@ TclCompileLreplaceCmd(
idx1 = 0;
goto replaceTail;
} else {
- if (idx1 > 0 && idx2 > 0 && idx2 < idx1) {
+ if (idx1 >= 0 && idx2 > 0 && idx2 < idx1) {
idx2 = idx1 - 1;
} else if (idx1 < 0 && idx2 < 0 && idx2 < idx1) {
idx2 = idx1 - 1;
diff --git a/tests/lreplace.test b/tests/lreplace.test
index b976788..44f3ac2 100644
--- a/tests/lreplace.test
+++ b/tests/lreplace.test
@@ -137,6 +137,12 @@ test lreplace-4.1 {Bug ccc2c2cc98: lreplace edge case} {
test lreplace-4.2 {Bug ccc2c2cc98: lreplace edge case} {
lreplace { } 1 1
} {}
+test lreplace-4.3 {lreplace edge case} {
+ lreplace {1 2 3} 2 0
+} {1 2 3}
+test lreplace-4.4 {lreplace edge case} {
+ lreplace {1 2 3 4 5} 3 1
+} {1 2 3 4 5}
# cleanup
catch {unset foo}