diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-09-11 21:37:34 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-09-11 21:37:34 (GMT) |
| commit | fcfbc3a606dd31e90fcc3a6bb847042e19e1722b (patch) | |
| tree | b7a14463d7ab14e98e9279ad3b8ed8568e4e0184 | |
| parent | 6b095954a1ca589409f43ac81e16b65727ddbbcb (diff) | |
| download | tcl-fcfbc3a606dd31e90fcc3a6bb847042e19e1722b.zip tcl-fcfbc3a606dd31e90fcc3a6bb847042e19e1722b.tar.gz tcl-fcfbc3a606dd31e90fcc3a6bb847042e19e1722b.tar.bz2 | |
complete the fix
| -rw-r--r-- | generic/tclIO.c | 20 | ||||
| -rw-r--r-- | tests/io.test | 8 |
2 files changed, 23 insertions, 5 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c index 5313eed..c6402f1 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -4335,6 +4335,7 @@ Write( char *nextNewLine = NULL; int endEncoding, saved = 0, total = 0, flushed = 0, needNlFlush = 0; char safe[BUFFER_PADDING]; + int encodingError = 0; if (srcLen) { WillWrite(chanPtr); @@ -4351,7 +4352,7 @@ Write( nextNewLine = (char *)memchr(src, '\n', srcLen); } - while (srcLen + saved + endEncoding > 0) { + while (srcLen + saved + endEncoding > 0 && !encodingError) { ChannelBuffer *bufPtr; char *dst; int result, srcRead, dstLen, dstWrote, srcLimit = srcLen; @@ -4390,6 +4391,19 @@ Write( statePtr->outputEncodingFlags &= ~TCL_ENCODING_START; + /* + * See io-75.2, TCL bug 6978c01b65. + * Check, if an encoding error occured and should be reported to the + * script level. + * This happens, if a written character may not be represented by the + * current output encoding and strict encoding is active. + */ + + if (result == TCL_CONVERT_UNKNOWN) { + encodingError = 1; + result = TCL_OK; + } + if ((result != TCL_OK) && (srcRead + dstWrote == 0)) { /* * We're reading from invalid/incomplete UTF-8. @@ -4497,6 +4511,10 @@ Write( UpdateInterest(chanPtr); + if (encodingError) { + Tcl_SetErrno(EILSEQ); + return -1; + } return total; } diff --git a/tests/io.test b/tests/io.test index 3d6b0da..cd04b115 100644 --- a/tests/io.test +++ b/tests/io.test @@ -8977,14 +8977,14 @@ test io-75.2 {unrepresentable character write passes and is replaced by ?} -setu set f [open $fn w+] fconfigure $f -encoding iso8859-1 } -body { - puts -nonewline $f "A\u2022" + catch {puts -nonewline $f "A\u2022"} msg flush $f seek $f 0 - read $f + list [read $f] $msg } -cleanup { close $f - removeFile io-75.2 -} -returnCodes ok -result "A" + removeFile io-75.5 +} -match glob -result [list {A} {error writing "*": illegal byte sequence}] # Incomplete sequence test. # This error may IMHO only be detected with the close. |
