summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclEncoding.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index 9896f85..0ec0649 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -2485,10 +2485,16 @@ Utf16ToUtfProc(
charLimit = *dstCharsPtr;
}
result = TCL_OK;
- if ((srcLen % sizeof(unsigned short)) != 0) {
+
+ /* check alignment with utf-16 (2 == sizeof(UTF-16)) */
+ if ((srcLen % 2) != 0) {
+ result = TCL_CONVERT_MULTIBYTE;
+ srcLen--;
+ }
+ /* If last code point is a high surrogate, we cannot handle that yet */
+ if ((srcLen >= 2) && ((src[srcLen - (clientData?1:2)] & 0xFC) == 0xD8)) {
result = TCL_CONVERT_MULTIBYTE;
- srcLen /= sizeof(unsigned short);
- srcLen *= sizeof(unsigned short);
+ srcLen-= 2;
}
srcStart = src;