diff options
author | dgp <dgp@users.sourceforge.net> | 2014-12-23 16:57:02 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2014-12-23 16:57:02 (GMT) |
commit | 55d2a945520134752ca2093461c1272fd08c32d2 (patch) | |
tree | 40df43ce60ee96719f77b3d4f2bcf623f58f9477 /generic/tclIO.c | |
parent | b49e834f28c9fd688fa615cb5809549c58f65788 (diff) | |
download | tcl-55d2a945520134752ca2093461c1272fd08c32d2.zip tcl-55d2a945520134752ca2093461c1272fd08c32d2.tar.gz tcl-55d2a945520134752ca2093461c1272fd08c32d2.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.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 |