diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-04-28 20:39:35 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-04-28 20:39:35 (GMT) |
commit | f57801a3b05da369c26d5f21a5907d066b5f4f63 (patch) | |
tree | 821220437def493a66c0a13598c89d15180be7f7 /generic | |
parent | e71aa6771eb99006cbe78b6dd13a0e1b1828e64f (diff) | |
download | tcl-f57801a3b05da369c26d5f21a5907d066b5f4f63.zip tcl-f57801a3b05da369c26d5f21a5907d066b5f4f63.tar.gz tcl-f57801a3b05da369c26d5f21a5907d066b5f4f63.tar.bz2 |
Extend "testutfnext" test-command such that it can detect when it reads more bytes than the end of the string.
If you want to null-terminate string explitely, use \x00
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclTest.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/generic/tclTest.c b/generic/tclTest.c index 42eff25..2178647 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -6841,13 +6841,13 @@ TestUtfNextCmd( } } - if (numBytes > (int)sizeof(buffer)-2) { - Tcl_AppendResult(interp, "\"testutfnext\" can only handle 30 bytes", NULL); + if (numBytes > (int)sizeof(buffer)-3) { + Tcl_AppendResult(interp, "\"testutfnext\" can only handle 29 bytes", NULL); return TCL_ERROR; } memcpy(buffer + 1, bytes, numBytes); - buffer[0] = buffer[numBytes + 1] = '\x00'; + buffer[0] = buffer[numBytes + 1] = buffer[numBytes + 2] = '\x00'; first = result = TclUtfNext(buffer + 1); while ((buffer[0] = *p++) != '\0') { @@ -6858,6 +6858,15 @@ TestUtfNextCmd( return TCL_ERROR; } } + p = tobetested; + while ((buffer[numBytes + 1] = *p++) != '\0') { + /* Run Tcl_UtfNext with many more possible bytes at src[end], all should give the same result */ + result = TclUtfNext(buffer + 1); + if (first != result) { + Tcl_AppendResult(interp, "Tcl_UtfNext is not supposed to read src[end]", NULL); + return TCL_ERROR; + } + } Tcl_SetObjResult(interp, Tcl_NewIntObj(first - buffer - 1)); |