diff options
author | dgp <dgp@users.sourceforge.net> | 2020-04-03 20:56:42 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2020-04-03 20:56:42 (GMT) |
commit | 2bc844ee6103b696341a49471260cd58963a0b51 (patch) | |
tree | 8641005660537a418246a049e6b11d1fadc54b0f /generic/tclTest.c | |
parent | 63ec99cd74c727ff07213127dd09d2d48e7736b1 (diff) | |
download | tcl-2bc844ee6103b696341a49471260cd58963a0b51.zip tcl-2bc844ee6103b696341a49471260cd58963a0b51.tar.gz tcl-2bc844ee6103b696341a49471260cd58963a0b51.tar.bz2 |
Fix testing command [testnumutfchars] so it cannot overrun the buffer.
Diffstat (limited to 'generic/tclTest.c')
-rw-r--r-- | generic/tclTest.c | 10 |
1 files changed, 7 insertions, 3 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; |