summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authoroehhar <harald.oehlmann@elmicron.de>2023-11-20 13:15:41 (GMT)
committeroehhar <harald.oehlmann@elmicron.de>2023-11-20 13:15:41 (GMT)
commitee8ac648cb65c6e491229e0192fa5b7b4b6e3d06 (patch)
treebb91e7591a3f048d2a089090ba80ce994c38398e /generic
parent55fd12924efbf331022d887c93f7c6595a575bfc (diff)
downloadtcl-ee8ac648cb65c6e491229e0192fa5b7b4b6e3d06.zip
tcl-ee8ac648cb65c6e491229e0192fa5b7b4b6e3d06.tar.gz
tcl-ee8ac648cb65c6e491229e0192fa5b7b4b6e3d06.tar.bz2
Bug [a173f922]: fix bug: fcopy does not write leading correct chars on later encoding error.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIO.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index bc1b1c6..884f4a8 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -9802,6 +9802,7 @@ CopyData(
ChannelState *inStatePtr, *outStatePtr;
int result = TCL_OK;
Tcl_Size sizeb;
+ Tcl_Size sizePart;
Tcl_WideInt total;
int size;
const char *buffer;
@@ -9888,6 +9889,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 */
}