diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-12 21:22:22 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-12 21:22:22 (GMT) |
commit | 2c687a4d1dab413946286ec99e093cbe85e8a7c5 (patch) | |
tree | 46efb700cb96107ee7f1ccdafbbf40c74ff0bac9 | |
parent | e47d4943353da4de3f0faf8dd95139d2ed4f7260 (diff) | |
parent | 99c0854650e170e35db77c4984ab41fb6b398f26 (diff) | |
download | tcl-2c687a4d1dab413946286ec99e093cbe85e8a7c5.zip tcl-2c687a4d1dab413946286ec99e093cbe85e8a7c5.tar.gz tcl-2c687a4d1dab413946286ec99e093cbe85e8a7c5.tar.bz2 |
Merge 8.7
-rw-r--r-- | doc/Utf.3 | 3 | ||||
-rw-r--r-- | generic/tclUtf.c | 21 |
2 files changed, 13 insertions, 11 deletions
@@ -283,7 +283,8 @@ byte \fIsrc[0]\fR nor the byte \fIstart[-1]\fR nor the byte Pascal Ord() function. It returns the Unicode character represented at the specified character (not byte) \fIindex\fR in the UTF-8 string \fIsrc\fR. The source string must contain at least \fIindex\fR -characters. +characters. If \fIindex\fR is TCL_INDEX_NONE or \fIindex\fR points +to the second half of a surrogate pair, it returns -1. .PP \fBTcl_UtfAtIndex\fR returns a pointer to the specified character (not byte) \fIindex\fR in the UTF-8 string \fIsrc\fR. The source string must diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 74e7888..fde80ae 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -1146,18 +1146,19 @@ Tcl_UniCharAtIndex( Tcl_UniChar ch = 0; int i = 0; - if (index != TCL_INDEX_NONE) { - while (index--) { - i = TclUtfToUniChar(src, &ch); - src += i; - } + if (index == TCL_INDEX_NONE) { + return -1; + } + while (index--) { + i = TclUtfToUniChar(src, &ch); + src += i; + } #if TCL_UTF_MAX <= 3 - if ((ch >= 0xD800) && (i < 3)) { - /* Index points at character following high Surrogate */ - return -1; - } -#endif + if ((ch >= 0xD800) && (i < 3)) { + /* Index points at character following high Surrogate */ + return -1; } +#endif TclUtfToUCS4(src, &i); return i; } |