diff options
| author | dgp@users.sourceforge.net <dgp> | 2014-12-23 16:57:02 (GMT) |
|---|---|---|
| committer | dgp@users.sourceforge.net <dgp> | 2014-12-23 16:57:02 (GMT) |
| commit | 25c010db735cbf6e820482b7b62bc85833f85a41 (patch) | |
| tree | 40df43ce60ee96719f77b3d4f2bcf623f58f9477 | |
| parent | b9baba0a1d488e937cc35c335f9fdf9de81da562 (diff) | |
| download | tcl-25c010db735cbf6e820482b7b62bc85833f85a41.zip tcl-25c010db735cbf6e820482b7b62bc85833f85a41.tar.gz tcl-25c010db735cbf6e820482b7b62bc85833f85a41.tar.bz2 | |
Use the new TCL_ENCODING_CHAR_LIMIT flag to have the encoding system manage
the max chars to read constraint.
| -rw-r--r-- | generic/tclIO.c | 15 |
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 |
