summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2018-03-07 21:02:44 (GMT)
committerdgp <dgp@users.sourceforge.net>2018-03-07 21:02:44 (GMT)
commitce6aa3ea082e901341852037de6a866850f28351 (patch)
tree1e5300d13be05d44b0592d1c08bec7b2545565b7 /generic
parentd7f41b448c046d176a3b6a931a12d09d7e75b626 (diff)
downloadtcl-ce6aa3ea082e901341852037de6a866850f28351.zip
tcl-ce6aa3ea082e901341852037de6a866850f28351.tar.gz
tcl-ce6aa3ea082e901341852037de6a866850f28351.tar.bz2
When index parsing alone tells you a [string range] is empty, just push it.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclCompCmdsSZ.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c
index d10d1c1..f98d375 100644
--- a/generic/tclCompCmdsSZ.c
+++ b/generic/tclCompCmdsSZ.c
@@ -930,6 +930,9 @@ TclCompileStringRangeCmd(
fromTokenPtr = TokenAfter(stringTokenPtr);
toTokenPtr = TokenAfter(fromTokenPtr);
+ /* Every path must push the string argument */
+ CompileWord(envPtr, stringTokenPtr, interp, 1);
+
/*
* Parse the two indices.
*/
@@ -942,6 +945,14 @@ TclCompileStringRangeCmd(
* Token parsed as an index expression. We treat all indices before
* the string the same as the start of the string.
*/
+
+ if (idx1 == TCL_INDEX_AFTER) {
+ /* [string range $s end+1 $last] must be empty string */
+ OP( POP);
+ PUSH( "");
+ return TCL_OK;
+ }
+
if (TclGetIndexFromToken(toTokenPtr, &idx2, TCL_INDEX_BEFORE,
TCL_INDEX_END) != TCL_OK) {
goto nonConstantIndices;
@@ -950,12 +961,17 @@ TclCompileStringRangeCmd(
* Token parsed as an index expression. We treat all indices after
* the string the same as the end of the string.
*/
+ if (idx2 == TCL_INDEX_BEFORE) {
+ /* [string range $s $first -1] must be empty string */
+ OP( POP);
+ PUSH( "");
+ return TCL_OK;
+ }
/*
* Push the operand onto the stack and then the substring operation.
*/
- CompileWord(envPtr, stringTokenPtr, interp, 1);
OP44( STR_RANGE_IMM, idx1, idx2);
return TCL_OK;
@@ -964,7 +980,6 @@ TclCompileStringRangeCmd(
*/
nonConstantIndices:
- CompileWord(envPtr, stringTokenPtr, interp, 1);
CompileWord(envPtr, fromTokenPtr, interp, 2);
CompileWord(envPtr, toTokenPtr, interp, 3);
OP( STR_RANGE);