summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-03-21 16:54:19 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-03-21 16:54:19 (GMT)
commit4f5ae9bf24ee4d8e6a6ef358b0e0b8de76968a2e (patch)
treeb4ec1d31b847455213aa61ffff3bb6f1ac274769 /generic/tclIO.c
parentafdd59e3580b6a38098fa8faac3db12052f232d8 (diff)
parent9152d5eec0903e1bb99607fa9a87e2453a25e13d (diff)
downloadtcl-4f5ae9bf24ee4d8e6a6ef358b0e0b8de76968a2e.zip
tcl-4f5ae9bf24ee4d8e6a6ef358b0e0b8de76968a2e.tar.gz
tcl-4f5ae9bf24ee4d8e6a6ef358b0e0b8de76968a2e.tar.bz2
Merge 8.7
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index ac624c1..880477b 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -6049,6 +6049,23 @@ DoReadChars(
statePtr->inQueueTail = NULL;
}
}
+
+ /*
+ * If CHANNEL_ENCODING_ERROR and CHANNEL_STICKY_EOF are both set,
+ * then CHANNEL_ENCODING_ERROR was caused by data that occurred
+ * after the EOF character was encountered, so it doesn't count as
+ * a real error.
+ */
+
+ if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR)
+ && !GotFlag(statePtr, CHANNEL_STICKY_EOF)
+ && !GotFlag(statePtr, CHANNEL_NONBLOCKING)) {
+ /* Channel is blocking. Return an error so that callers
+ * like [read] can return an error.
+ */
+ Tcl_SetErrno(EILSEQ);
+ goto finish;
+ }
}
if (copiedNow < 0) {
@@ -6079,6 +6096,7 @@ DoReadChars(
}
}
+finish:
/*
* Failure to fill a channel buffer may have left channel reporting a
* "blocked" state, but so long as we fulfilled the request here, the
@@ -6112,6 +6130,11 @@ DoReadChars(
assert(!(GotFlag(statePtr, CHANNEL_EOF|CHANNEL_BLOCKED)
== (CHANNEL_EOF|CHANNEL_BLOCKED)));
UpdateInterest(chanPtr);
+ if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR)
+ && (!copied || !GotFlag(statePtr, CHANNEL_NONBLOCKING))) {
+ Tcl_SetErrno(EILSEQ);
+ copied = -1;
+ }
TclChannelRelease((Tcl_Channel)chanPtr);
return copied;
}
@@ -6742,11 +6765,14 @@ TranslateInputEOL(
* EOF character was seen in EOL translated range. Leave current file
* position pointing at the EOF character, but don't store the EOF
* character in the output string.
+ *
+ * If CHANNEL_ENCODING_ERROR is set, it can only be because of data
+ * encountered after the EOF character, so it is nonsense. Unset it.
*/
SetFlag(statePtr, CHANNEL_EOF | CHANNEL_STICKY_EOF);
statePtr->inputEncodingFlags |= TCL_ENCODING_END;
- ResetFlag(statePtr, CHANNEL_BLOCKED|INPUT_SAW_CR);
+ ResetFlag(statePtr, CHANNEL_BLOCKED|INPUT_SAW_CR|CHANNEL_ENCODING_ERROR);
}
}