summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-05-16 15:10:37 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-05-16 15:10:37 (GMT)
commit2c48da76fc7efc47bef33eff275ecfbf80ccd2a8 (patch)
treecb8358bfc5ee832a31aed3053d4419bd60aa579c /generic/tclIO.c
parent80d6e099f04cbbbf778e8efd20507f8b4902fda6 (diff)
parent42ba1ff27ede658e6f4b9d80c5c6c2734dcb39bf (diff)
downloadtcl-2c48da76fc7efc47bef33eff275ecfbf80ccd2a8.zip
tcl-2c48da76fc7efc47bef33eff275ecfbf80ccd2a8.tar.gz
tcl-2c48da76fc7efc47bef33eff275ecfbf80ccd2a8.tar.bz2
merge 8.5
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c46
1 files changed, 37 insertions, 9 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 0ba4098..8545912 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -5904,7 +5904,6 @@ ReadChars(
* record \r or \n yet.
*/
- assert(dstRead + 1 == dstDecoded);
assert(dst[dstRead] == '\r');
assert(statePtr->inputTranslation == TCL_TRANSLATE_CRLF);
@@ -5925,7 +5924,6 @@ ReadChars(
assert(dstWrote == 0);
assert(dstRead == 0);
- assert(dstDecoded == 1);
/*
* We decoded only the bare cr, and we cannot read a
@@ -5980,6 +5978,13 @@ ReadChars(
return 1;
}
+ /*
+ * Revise the dstRead value so that the numChars calc
+ * below correctly computes zero characters read.
+ */
+
+ dstRead = numChars;
+
/* FALL THROUGH - get more data (dstWrote == 0) */
}
@@ -6006,16 +6011,38 @@ ReadChars(
}
if (dstWrote == 0) {
+ ChannelBuffer *nextPtr;
- /*
- * We were not able to read any chars. Maybe there were
- * not enough src bytes to decode into a char. Maybe
- * a lone \r could not be translated (crlf mode). Need
- * to combine any unused src bytes we have in the first
- * buffer with subsequent bytes to try again.
+ /* We were not able to read any chars. */
+
+ assert (numChars == 0);
+
+ /*
+ * There is one situation where this is the correct final
+ * result. If the src buffer contains only a single \n
+ * byte, and we are in TCL_TRANSLATE_AUTO mode, and
+ * when the translation pass was made the INPUT_SAW_CR
+ * flag was set on the channel. In that case, the
+ * correct behavior is to consume that \n and produce the
+ * empty string.
+ */
+
+ if (dst[0] == '\n') {
+ assert(statePtr->inputTranslation == TCL_TRANSLATE_AUTO);
+ assert(dstRead == 1);
+
+ goto consume;
+ }
+
+ /* Otherwise, reading zero characters indicates there's
+ * something incomplete at the end of the src buffer.
+ * Maybe there were not enough src bytes to decode into
+ * a char. Maybe a lone \r could not be translated (crlf
+ * mode). Need to combine any unused src bytes we have
+ * in the first buffer with subsequent bytes to try again.
*/
- ChannelBuffer *nextPtr = bufPtr->nextPtr;
+ nextPtr = bufPtr->nextPtr;
if (nextPtr == NULL) {
if (srcLen > 0) {
@@ -6052,6 +6079,7 @@ ReadChars(
statePtr->inputEncodingFlags &= ~TCL_ENCODING_START;
+ consume:
bufPtr->nextRemoved += srcRead;
if (dstWrote > srcRead + 1) {
*factorPtr = dstWrote * UTF_EXPANSION_FACTOR / srcRead;