summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2017-06-08 16:48:33 (GMT)
committerdgp <dgp@users.sourceforge.net>2017-06-08 16:48:33 (GMT)
commit15c693307b87a299e50ff1d544b412488dee9485 (patch)
tree40a0b70a3214bf80334b41351e7564d2d81ad60c /generic
parente760092378d4b34b2f4cbd66a613128dbd703258 (diff)
parent381ed7be7a4f2a552dd98af85e52f489f1f077ba (diff)
downloadtcl-15c693307b87a299e50ff1d544b412488dee9485.zip
tcl-15c693307b87a299e50ff1d544b412488dee9485.tar.gz
tcl-15c693307b87a299e50ff1d544b412488dee9485.tar.bz2
merge trunk
Diffstat (limited to 'generic')
-rw-r--r--generic/tclTest.c2
-rw-r--r--generic/tclUtf.c27
2 files changed, 15 insertions, 14 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 547dc9a..ebd90ae 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -6836,7 +6836,7 @@ TestNumUtfCharsCmd(
int len = -1;
if (objc > 2) {
- (void) Tcl_GetStringFromObj(objv[1], &len);
+ (void) Tcl_GetIntFromObj(interp, objv[2], &len);
}
len = Tcl_NumUtfChars(Tcl_GetString(objv[1]), len);
Tcl_SetObjResult(interp, Tcl_NewIntObj(len));
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;
}