diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-02-22 07:28:27 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-02-22 07:28:27 (GMT) |
commit | f0284298add52f9e6804e1d3e53c4e67fcfbc1c3 (patch) | |
tree | fd61e54f92d80b8da24202bfaa10aea0fd4776b8 /generic | |
parent | 03a9d6928d201038d4fa4dbccc9bc724c0dcd713 (diff) | |
parent | 23d9ca0ec4772f703cd24c476d5fa485fd91e828 (diff) | |
download | tcl-f0284298add52f9e6804e1d3e53c4e67fcfbc1c3.zip tcl-f0284298add52f9e6804e1d3e53c4e67fcfbc1c3.tar.gz tcl-f0284298add52f9e6804e1d3e53c4e67fcfbc1c3.tar.bz2 |
Fix [5607d6482c]: strict ucs-2 never implemented (TIP #346/#656)
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclEncoding.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 1d3a3eb..d2b0efc 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -573,13 +573,13 @@ TclInitEncodingSubsystem(void) type.freeProc = NULL; type.nullSize = 2; type.encodingName = "ucs-2le"; - type.clientData = INT2PTR(TCL_ENCODING_LE|TCL_ENCODING_NOCOMPLAIN); + type.clientData = INT2PTR(TCL_ENCODING_LE); Tcl_CreateEncoding(&type); type.encodingName = "ucs-2be"; - type.clientData = INT2PTR(TCL_ENCODING_NOCOMPLAIN); + type.clientData = INT2PTR(0); Tcl_CreateEncoding(&type); type.encodingName = "ucs-2"; - type.clientData = INT2PTR(isLe.c|TCL_ENCODING_NOCOMPLAIN); + type.clientData = INT2PTR(isLe.c); Tcl_CreateEncoding(&type); type.toUtfProc = Utf32ToUtfProc; @@ -601,13 +601,13 @@ TclInitEncodingSubsystem(void) type.freeProc = NULL; type.nullSize = 2; type.encodingName = "utf-16le"; - type.clientData = INT2PTR(TCL_ENCODING_LE); + type.clientData = INT2PTR(TCL_ENCODING_LE|ENCODING_UTF); Tcl_CreateEncoding(&type); type.encodingName = "utf-16be"; - type.clientData = INT2PTR(0); + type.clientData = INT2PTR(ENCODING_UTF); Tcl_CreateEncoding(&type); type.encodingName = "utf-16"; - type.clientData = INT2PTR(isLe.c); + type.clientData = INT2PTR(isLe.c|ENCODING_UTF); Tcl_CreateEncoding(&type); #ifndef TCL_NO_DEPRECATED @@ -2984,10 +2984,7 @@ UtfToUcs2Proc( * output buffer. */ { const char *srcStart, *srcEnd, *srcClose, *dstStart, *dstEnd; - int result, numChars; -#if TCL_UTF_MAX < 4 - int len; -#endif + int result, numChars, len; Tcl_UniChar ch = 0; flags |= PTR2INT(clientData); @@ -3017,17 +3014,32 @@ UtfToUcs2Proc( break; } #if TCL_UTF_MAX < 4 - src += (len = TclUtfToUniChar(src, &ch)); + len = TclUtfToUniChar(src, &ch); if ((ch >= 0xD800) && (len < 3)) { + if (STOPONERROR) { + result = TCL_CONVERT_UNKNOWN; + break; + } + src += len; src += TclUtfToUniChar(src, &ch); ch = 0xFFFD; } #else - src += TclUtfToUniChar(src, &ch); + len = TclUtfToUniChar(src, &ch); if (ch > 0xFFFF) { + if (STOPONERROR) { + result = TCL_CONVERT_UNKNOWN; + break; + } ch = 0xFFFD; } #endif + if (STOPONERROR && ((ch & ~0x7FF) == 0xD800)) { + result = TCL_CONVERT_SYNTAX; + break; + } + + src += len; /* * Need to handle this in a way that won't cause misalignment by |