summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2021-03-19 13:19:04 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2021-03-19 13:19:04 (GMT)
commit0b7abfd9bc2564c12aa0675058917dc7f7727082 (patch)
treeb77352df51ab65786ec59f2d00f5849051921e53 /generic/tclEncoding.c
parent1df5f1053536d20ad31fac5c678647258b61c24f (diff)
parentd5479489aab71c267a1371d2ac1d0674a15a0c61 (diff)
downloadtcl-0b7abfd9bc2564c12aa0675058917dc7f7727082.zip
tcl-0b7abfd9bc2564c12aa0675058917dc7f7727082.tar.gz
tcl-0b7abfd9bc2564c12aa0675058917dc7f7727082.tar.bz2
Merge 8.7
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index a1b6fe5..1bc1360 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -2163,7 +2163,7 @@ UtfToUtfProc(
result = TCL_CONVERT_NOSPACE;
break;
}
- if ((UCHAR(*src - 1) < 0x7F) && !(flags & TCL_ENCODING_EXTERNAL)) {
+ if (UCHAR(*src) < 0x80 && !(UCHAR(*src) == 0 && !(flags & TCL_ENCODING_EXTERNAL))) {
/*
* Copy 7bit characters, but skip null-bytes when we are in input
* mode, so that they get converted to 0xC080.
@@ -2194,14 +2194,19 @@ UtfToUtfProc(
src += 1;
dst += Tcl_UniCharToUtf(ch, dst);
} else {
- src += TclUtfToUCS4(src, &ch);
+ size_t len = TclUtfToUCS4(src, &ch);
+ if ((len < 2) && (ch != 0) && (flags & TCL_ENCODING_STOPONERROR)) {
+ result = TCL_CONVERT_SYNTAX;
+ break;
+ }
+ src += len;
if ((ch | 0x7FF) == 0xDFFF) {
/*
* A surrogate character is detected, handle especially.
*/
int low = ch;
- size_t len = (src <= srcEnd-3) ? TclUtfToUCS4(src, &low) : 0;
+ len = (src <= srcEnd-3) ? TclUtfToUCS4(src, &low) : 0;
if (((low & ~0x3FF) != 0xDC00) || (ch & 0x400)) {
*dst++ = (char) (((ch >> 12) | 0xE0) & 0xEF);