From ce6aa3ea082e901341852037de6a866850f28351 Mon Sep 17 00:00:00 2001 From: dgp Date: Wed, 7 Mar 2018 21:02:44 +0000 Subject: When index parsing alone tells you a [string range] is empty, just push it. --- generic/tclCompCmdsSZ.c | 19 +++++++++++++++++-- 1 file 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); -- cgit v0.12