diff options
author | oehhar <harald.oehlmann@elmicron.de> | 2023-11-20 13:55:31 (GMT) |
---|---|---|
committer | oehhar <harald.oehlmann@elmicron.de> | 2023-11-20 13:55:31 (GMT) |
commit | 23c8c9bc2cb4ac9d281ea38238932cfac707a27e (patch) | |
tree | 3959b5414136587cc07db9f893bed1610a9adfcb /generic/tclIO.c | |
parent | edcc6e521c7581edaee0528ee5f7ec5975fe00a6 (diff) | |
parent | ee5350e804935ff2c79ed4d6f85a0b205e7a7915 (diff) | |
download | tcl-23c8c9bc2cb4ac9d281ea38238932cfac707a27e.zip tcl-23c8c9bc2cb4ac9d281ea38238932cfac707a27e.tar.gz tcl-23c8c9bc2cb4ac9d281ea38238932cfac707a27e.tar.bz2 |
Fix bug [a173f922]: fcopy does not write leading correct chars on later encoding error.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r-- | generic/tclIO.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c index d7b9513..b480377 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -9687,6 +9687,7 @@ CopyData( ChannelState *inStatePtr, *outStatePtr; int result = TCL_OK; Tcl_Size sizeb; + Tcl_Size sizePart; Tcl_WideInt total; Tcl_WideInt size; const char *buffer; @@ -9768,6 +9769,23 @@ CopyData( size = DoReadChars(inStatePtr->topChanPtr, bufObj, sizeb, !GotFlag(inStatePtr, CHANNEL_NONBLOCKING) ,0 /* No append */); + /* + * In case of a recoverable encoding error, any data before + * the error should be written. This data is in the bufObj. + * Program flow for this case: + * - Check, if there are any remaining bytes to write + * - If yes, simulate a successful read to write them out + * - Come back here by the outer loop and read again + * - Do not enter in the if below, as there are no pending + * writes + * - Fail below with a read error + */ + if (size < 0 && Tcl_GetErrno() == EILSEQ) { + Tcl_GetStringFromObj(bufObj, &sizePart); + if (sizePart > 0) { + size = sizePart; + } + } } underflow = (size >= 0) && (size < sizeb); /* Input underflow */ } |