From 7110b5a18c09fdf57b9da18e5a8cf60ee43b1430 Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 13 Apr 2020 16:44:07 +0000 Subject: New test demonstrating Tcl_StringCaseMatch is botched in its use of Tcl_UtfPrev. It doesn't consider multi-byte characters at all, let alone anything malformed. Good thing the call isn't needed at all. --- tests/util.test | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/util.test b/tests/util.test index 46d9152..85c06dd 100644 --- a/tests/util.test +++ b/tests/util.test @@ -378,6 +378,10 @@ test util-5.50 {Tcl_StringMatch} { test util-5.51 {Tcl_StringMatch} { Wrapper_Tcl_StringMatch "" "" } 1 +test util-5.52 {Tcl_StringMatch} { + Wrapper_Tcl_StringMatch \[a\u0000 a\x80 +} 0 + test util-6.1 {Tcl_PrintDouble - using tcl_precision} -setup { set old_precision $::tcl_precision -- cgit v0.12 From ff424481242afe72a43040e49520fcfebe00e6c1 Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 13 Apr 2020 16:51:34 +0000 Subject: [a7f685a181] Eliminate botched call of Tcl_UtfPrev. --- generic/tclUtil.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 82ef9b7..3dd9a32 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -1980,7 +1980,6 @@ Tcl_StringCaseMatch( int nocase) /* 0 for case sensitive, 1 for insensitive */ { int p, charLen; - CONST char *pstart = pattern; Tcl_UniChar ch1, ch2; while (1) { @@ -2145,10 +2144,13 @@ Tcl_StringCaseMatch( break; } } + /* If we reach here, we matched. Need to move past closing ] */ while (*pattern != ']') { if (*pattern == '\0') { - pattern = Tcl_UtfPrev(pattern, pstart); - break; + /* We ran out of pattern after matching something in + * (unclosed!) brackets. So long as we ran out of string + * at the same time, we have a match. Otherwise, not. */ + return (*str == '\0'); } pattern++; } -- cgit v0.12