summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclTest.c12
-rw-r--r--generic/tclUtf.c5
2 files changed, 14 insertions, 3 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 03b5717..aaadc1d 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -6819,12 +6819,18 @@ TestNumUtfCharsCmd(
Tcl_Obj *const objv[])
{
if (objc > 1) {
- int len = -1;
+ int numBytes, len, limit = -1;
+ const char *bytes = Tcl_GetStringFromObj(objv[1], &numBytes);
if (objc > 2) {
- (void) Tcl_GetIntFromObj(interp, objv[2], &len);
+ if (TclGetIntForIndex(interp, objv[2], numBytes, &limit) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (limit > numBytes + 1) {
+ limit = numBytes + 1;
+ }
}
- len = Tcl_NumUtfChars(Tcl_GetString(objv[1]), len);
+ len = Tcl_NumUtfChars(bytes, limit);
Tcl_SetObjResult(interp, Tcl_NewIntObj(len));
}
return TCL_OK;
diff --git a/generic/tclUtf.c b/generic/tclUtf.c
index a8b04bf..6526645 100644
--- a/generic/tclUtf.c
+++ b/generic/tclUtf.c
@@ -64,8 +64,13 @@ static const unsigned char totalBytes[256] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+#if TCL_UTF_MAX > 3
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+#else /* Tcl_UtfCharComplete() might point to 2nd byte of valid 4-byte sequence */
+ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
+ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
+#endif
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,1,1,1,1,1,1,1,1,1,1,1
};