summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authoroehhar <harald.oehlmann@elmicron.de>2023-11-20 13:36:40 (GMT)
committeroehhar <harald.oehlmann@elmicron.de>2023-11-20 13:36:40 (GMT)
commitee5350e804935ff2c79ed4d6f85a0b205e7a7915 (patch)
tree4430b7baf3d0eb3bd90404e69470d8fb730978de /generic/tclIO.c
parentc3de06ef3212fee8a8d4b4fed7ec8b2fc2b8273d (diff)
parent88a32b8959860e8891f73548cc49b33749949a8f (diff)
downloadtcl-ee5350e804935ff2c79ed4d6f85a0b205e7a7915.zip
tcl-ee5350e804935ff2c79ed4d6f85a0b205e7a7915.tar.gz
tcl-ee5350e804935ff2c79ed4d6f85a0b205e7a7915.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.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 0047f0b..3b36457 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -9829,6 +9829,7 @@ CopyData(
ChannelState *inStatePtr, *outStatePtr;
int result = TCL_OK;
Tcl_Size sizeb;
+ Tcl_Size sizePart;
Tcl_WideInt total;
int size;
const char *buffer;
@@ -9915,6 +9916,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 */
}