diff options
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r-- | generic/tclEncoding.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 1bed847..0f5337e 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -2414,18 +2414,19 @@ UtfToUtfProc( dst += Tcl_UniCharToUtf(*chPtr, dst); } else { src += TclUtfToUniChar(src, chPtr); - if ((*chPtr | 0x3FF) == 0xDBFF) { - /* A high surrogate character is detected, handle especially */ + if ((*chPtr | 0x7FF) == 0xDFFF) { + /* A surrogate character is detected, handle especially */ Tcl_UniChar low = *chPtr; - if (src <= srcEnd-3) { - Tcl_UtfToUniChar(src, &low); - } - if ((low | 0x3FF) != 0xDFFF) { + size_t len = (src <= srcEnd-3) ? Tcl_UtfToUniChar(src, &low) : 0; + if (((low | 0x3FF) != 0xDFFF) || (*chPtr & 0x400)) { *dst++ = (char) (((*chPtr >> 12) | 0xE0) & 0xEF); *dst++ = (char) (((*chPtr >> 6) | 0x80) & 0xBF); *dst++ = (char) ((*chPtr | 0x80) & 0xBF); continue; } + src += len; + dst += Tcl_UniCharToUtf(*chPtr, dst); + *chPtr = low; } dst += Tcl_UniCharToUtf(*chPtr, dst); } |