summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-12-23 16:57:02 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-12-23 16:57:02 (GMT)
commit7134cd9399b41471ebbd9126bab51e0ffd6cd9db (patch)
tree40df43ce60ee96719f77b3d4f2bcf623f58f9477 /generic/tclIO.c
parent1a92fb378c0e8060f433986fb0dc89bd04168a45 (diff)
downloadtcl-7134cd9399b41471ebbd9126bab51e0ffd6cd9db.zip
tcl-7134cd9399b41471ebbd9126bab51e0ffd6cd9db.tar.gz
tcl-7134cd9399b41471ebbd9126bab51e0ffd6cd9db.tar.bz2
Use the new TCL_ENCODING_CHAR_LIMIT flag to have the encoding system manage
the max chars to read constraint.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 79aa667..9bbf2a6 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -5977,16 +5977,21 @@ ReadChars(
*/
while (1) {
- int dstDecoded, dstRead, dstWrote, srcRead, numChars;
+ int dstDecoded, dstRead, dstWrote, srcRead, numChars, code;
+ int flags = statePtr->inputEncodingFlags | TCL_ENCODING_NO_TERMINATE;
+
+ if (charsToRead > 0) {
+ flags |= TCL_ENCODING_CHAR_LIMIT;
+ numChars = charsToRead;
+ }
/*
* Perform the encoding transformation. Read no more than
* srcLen bytes, write no more than dstLimit bytes.
*/
- int code = Tcl_ExternalToUtf(NULL, encoding, src, srcLen,
- (statePtr->inputEncodingFlags | TCL_ENCODING_NO_TERMINATE)
- & (bufPtr->nextPtr ? ~0 : ~TCL_ENCODING_END),
+ code = Tcl_ExternalToUtf(NULL, encoding, src, srcLen,
+ flags & (bufPtr->nextPtr ? ~0 : ~TCL_ENCODING_END),
&statePtr->inputEncodingState, dst, dstLimit, &srcRead,
&dstDecoded, &numChars);
@@ -6161,6 +6166,8 @@ ReadChars(
if (charsToRead > 0 && numChars > charsToRead) {
/*
+ * TODO: This cannot happen anymore.
+ *
* We read more chars than allowed. Reset limits to
* prevent that and try again. Don't forget the extra
* padding of TCL_UTF_MAX bytes demanded by the