summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclTest.c10
-rw-r--r--tests/utf.test2
2 files changed, 8 insertions, 4 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 3e8cb6a..f63f891 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -6805,12 +6805,16 @@ 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);
+ (void) Tcl_GetIntFromObj(interp, objv[2], &limit);
+ if (limit > numBytes) {
+ limit = numBytes;
+ }
}
- 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/tests/utf.test b/tests/utf.test
index 2e4882d..5cd2277 100644
--- a/tests/utf.test
+++ b/tests/utf.test
@@ -137,7 +137,7 @@ test utf-4.9 {Tcl_NumUtfChars: #u20AC, calc len, incomplete} {testnumutfchars te
testnumutfchars [testbytestring "\xE2\x82\xAC"] 2
} {2}
test utf-4.10 {Tcl_NumUtfChars: #u0000, calc len, overcomplete} {testnumutfchars testbytestring} {
- testnumutfchars [testbytestring "\x00"] 2
+ testnumutfchars [testbytestring "\x00"] 1
} {2}
test utf-5.1 {Tcl_UtfFindFirst} {testfindfirst testbytestring} {