diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-06-08 12:38:56 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-06-08 12:38:56 (GMT) |
commit | 74d42f2fe9fc80e12aa490ffea731ac8114183b5 (patch) | |
tree | a27339ac3118a7718eb23d23b75ffbd9380bbe9a /generic/tclUtf.c | |
parent | 061893f84e1d06c45531c7a4d7a7384e144dc69b (diff) | |
parent | 4276e234955e8ecdc91fd5d2ebee1acbb35753ad (diff) | |
download | tcl-74d42f2fe9fc80e12aa490ffea731ac8114183b5.zip tcl-74d42f2fe9fc80e12aa490ffea731ac8114183b5.tar.gz tcl-74d42f2fe9fc80e12aa490ffea731ac8114183b5.tar.bz2 |
merge core-8-6-branch
Diffstat (limited to 'generic/tclUtf.c')
-rw-r--r-- | generic/tclUtf.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/generic/tclUtf.c b/generic/tclUtf.c index c46d250..161a4bd 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -459,7 +459,6 @@ Tcl_NumUtfChars( * for strlen(string). */ { Tcl_UniChar ch; - register Tcl_UniChar *chPtr = &ch; register int i; /* @@ -472,23 +471,25 @@ Tcl_NumUtfChars( i = 0; if (length < 0) { while (*src != '\0') { - src += TclUtfToUniChar(src, chPtr); + src += TclUtfToUniChar(src, &ch); i++; } + if (i < 0) i = INT_MAX; /* Bug [2738427] */ } else { - register int n; - - while (length > 0) { - if (UCHAR(*src) < 0xC0) { - length--; - src++; - } else { - n = Tcl_UtfToUniChar(src, chPtr); - length -= n; - src += n; - } + register const char *endPtr = src + length - TCL_UTF_MAX; + + while (src < endPtr) { + src += TclUtfToUniChar(src, &ch); i++; } + endPtr += TCL_UTF_MAX; + while ((src < endPtr) && Tcl_UtfCharComplete(src, endPtr - src)) { + src += TclUtfToUniChar(src, &ch); + i++; + } + if (src < endPtr) { + i += endPtr - src; + } } return i; } |