summaryrefslogtreecommitdiffstats
path: root/generic/tclUtf.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2020-05-07 21:47:28 (GMT)
committerdgp <dgp@users.sourceforge.net>2020-05-07 21:47:28 (GMT)
commit752f99d5762c8c78c12d48f81c36d7f2a4914e37 (patch)
treef894c2ee9fda48235ef2379adcdf5e99bf78546a /generic/tclUtf.c
parent6d36267ee03ebbf37b1843d0602220bbc299f8e9 (diff)
parent236622c790c99057427a8bc4fb83867cfbf4bc04 (diff)
downloadtcl-752f99d5762c8c78c12d48f81c36d7f2a4914e37.zip
tcl-752f99d5762c8c78c12d48f81c36d7f2a4914e37.tar.gz
tcl-752f99d5762c8c78c12d48f81c36d7f2a4914e37.tar.bz2
Merge changes from parent branch
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r--generic/tclUtf.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c
index 8ae4b15..b855844 100644
--- a/generic/tclUtf.c
+++ b/generic/tclUtf.c
@@ -525,12 +525,13 @@ Tcl_UtfToUniCharDString(
p += TclUtfToUniChar(p, &ch);
*w++ = ch;
}
- while ((p < endPtr) && Tcl_UtfCharComplete(p, endPtr-p)) {
- p += TclUtfToUniChar(p, &ch);
- *w++ = ch;
- }
while (p < endPtr) {
- *w++ = UCHAR(*p++);
+ if (Tcl_UtfCharComplete(p, endPtr-p)) {
+ p += TclUtfToUniChar(p, &ch);
+ *w++ = ch;
+ } else {
+ *w++ = UCHAR(*p++);
+ }
}
*w = '\0';
Tcl_DStringSetLength(dsPtr,
@@ -621,17 +622,18 @@ Tcl_NumUtfChars(
i++;
}
/* Loop over the remaining string where call must happen */
- while ((src < endPtr) && Tcl_UtfCharComplete(src, endPtr - src)) {
- src += TclUtfToUniChar(src, &ch);
+ while (src < endPtr) {
+ if (Tcl_UtfCharComplete(src, endPtr - src)) {
+ src += TclUtfToUniChar(src, &ch);
+ } else {
+ /*
+ * src points to incomplete UTF-8 sequence
+ * Treat first byte as character and count it
+ */
+ src++;
+ }
i++;
}
- if (src < endPtr) {
- /*
- * String ends in an incomplete UTF-8 sequence.
- * Count every byte in it.
- */
- i += endPtr - src;
- }
}
return i;
}