summaryrefslogtreecommitdiffstats
path: root/generic/tclUtf.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-05 11:44:32 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-05 11:44:32 (GMT)
commita2f768dce66fc3f48b9a095fdc121fc9cc20b23a (patch)
treec6667f8b54eb728927b95d2dc4d7f91d040f1a60 /generic/tclUtf.c
parent28840fbf89d8ec155bdbbd68d7919164083a77d0 (diff)
downloadtcl-a2f768dce66fc3f48b9a095fdc121fc9cc20b23a.zip
tcl-a2f768dce66fc3f48b9a095fdc121fc9cc20b23a.tar.gz
tcl-a2f768dce66fc3f48b9a095fdc121fc9cc20b23a.tar.bz2
Fix Tcl_UtfPrev() such that it can never go back more than TCL_UTF_MAX bytes. Already done correctly on core-8-6-branch, but this was never forwarded to core-8-branch.
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r--generic/tclUtf.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c
index 782657a..7b6ec63 100644
--- a/generic/tclUtf.c
+++ b/generic/tclUtf.c
@@ -815,13 +815,13 @@ Tcl_NumUtfChars(
}
if (i < 0) i = INT_MAX; /* Bug [2738427] */
} else {
- const char *endPtr = src + length - 4;
+ const char *endPtr = src + length - TCL_UTF_MAX;
while (src < endPtr) {
src += TclUtfToUniChar(src, &ch);
i++;
}
- endPtr += 4;
+ endPtr += TCL_UTF_MAX;
while ((src < endPtr) && Tcl_UtfCharComplete(src, endPtr - src)) {
src += TclUtfToUniChar(src, &ch);
i++;
@@ -1065,7 +1065,7 @@ Tcl_UtfPrev(
/* Continue the search backwards... */
look--;
- } while (trailBytesSeen < 4);
+ } while (trailBytesSeen < TCL_UTF_MAX);
/*
* We've seen TCL_UTF_MAX trail bytes, so we know there will not be a
@@ -1073,7 +1073,11 @@ Tcl_UtfPrev(
* accepting the fallback (for TCL_UTF_MAX > 3) or just go back as
* far as we can.
*/
+#if TCL_UTF_MAX > 3
return fallback;
+#else
+ return src - TCL_UTF_MAX;
+#endif
}
/*