summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclUtil.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index b3742f7..d40cbeb 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -1570,8 +1570,12 @@ static inline int
TrimRight(
const char *bytes, /* String to be trimmed... */
int numBytes, /* ...and its length in bytes */
+ /* Calls to TclUtfToUniChar() in this routine
+ * rely on (bytes[numBytes] == '\0'). */
const char *trim, /* String of trim characters... */
int numTrim) /* ...and its length in bytes */
+ /* Calls to TclUtfToUniChar() in this routine
+ * rely on (trim[numTrim] == '\0'). */
{
const char *pp, *p = bytes + numBytes;
@@ -1579,10 +1583,13 @@ TrimRight(
do {
Tcl_UniChar ch1;
const char *q = trim;
- int bytesLeft = numTrim;
+ int pInc = 0, bytesLeft = numTrim;
pp = Tcl_UtfPrev(p, bytes);
- (void)TclUtfToUniChar(pp, &ch1);
+ do {
+ pp += pInc;
+ pInc = TclUtfToUniChar(pp, &ch1);
+ } while (pp + pInc < p);
/* Inner loop: scan trim string for match to current character */
do {