summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-12 21:22:22 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-12 21:22:22 (GMT)
commit2c687a4d1dab413946286ec99e093cbe85e8a7c5 (patch)
tree46efb700cb96107ee7f1ccdafbbf40c74ff0bac9
parente47d4943353da4de3f0faf8dd95139d2ed4f7260 (diff)
parent99c0854650e170e35db77c4984ab41fb6b398f26 (diff)
downloadtcl-2c687a4d1dab413946286ec99e093cbe85e8a7c5.zip
tcl-2c687a4d1dab413946286ec99e093cbe85e8a7c5.tar.gz
tcl-2c687a4d1dab413946286ec99e093cbe85e8a7c5.tar.bz2
Merge 8.7
-rw-r--r--doc/Utf.33
-rw-r--r--generic/tclUtf.c21
2 files changed, 13 insertions, 11 deletions
diff --git a/doc/Utf.3 b/doc/Utf.3
index a7f60d2..26207ba 100644
--- a/doc/Utf.3
+++ b/doc/Utf.3
@@ -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;
}