summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclCmdMZ.c8
-rw-r--r--tests/switch.test7
2 files changed, 13 insertions, 2 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index 885df49..8a08f53 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -3760,8 +3760,12 @@ TclNRSwitchObjCmd(
if (matchVarObj != NULL) {
Tcl_Obj *substringObj;
- substringObj = Tcl_GetRange(stringObj,
- info.matches[j].start, info.matches[j].end-1);
+ if (info.matches[j].end + 1 > 1) {
+ substringObj = Tcl_GetRange(stringObj,
+ info.matches[j].start, info.matches[j].end-1);
+ } else {
+ TclNewObj(substringObj);
+ }
/*
* Never fails; the object is always clean at this point.
diff --git a/tests/switch.test b/tests/switch.test
index 2fce108..3d106c0 100644
--- a/tests/switch.test
+++ b/tests/switch.test
@@ -745,6 +745,13 @@ test switch-14.16 {switch -regexp compilation} {
}
}}
} no
+test switch-14.17 {switch -regexp bug [c0bc269178]} {
+ set result {}
+ switch -regexp -matchvar m -indexvar i ac {
+ {(a)(b)?(c)} {set result $m}
+ }
+ set result
+} {ac a {} c}
test switch-15.1 {coroutine safety of non-bytecoded switch} {*}{
-body {