summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-06-05 15:20:59 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-06-05 15:20:59 (GMT)
commit54eb626870a445ace6d45d1a897ebbe0860297e1 (patch)
treeccbe4772914cfca321c5dc9f2bfff37cdf777d18 /generic/tclIO.c
parent852f44abf1e24dce23b456d6cfa857bb5649300e (diff)
parent457182886821a26e8470e57319fa58d9b3f0deeb (diff)
downloadtcl-54eb626870a445ace6d45d1a897ebbe0860297e1.zip
tcl-54eb626870a445ace6d45d1a897ebbe0860297e1.tar.gz
tcl-54eb626870a445ace6d45d1a897ebbe0860297e1.tar.bz2
When too many chars are read by ReadChars() and we trim the limits to get it right on the next pass, don't forget the TCL_UTF_MAX padding demanded by Tcl_ExternalToUtf(). (Thanks for finding that, aku!) Fix the factorPtr management. It was just totaly wrong. The factor should be a ratio of the record of bytes read to the record of chars read. With those fixes, new test io-12.6 covers the "too many chars" code.
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 9197b06..6add83f 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -6016,10 +6016,13 @@ ReadChars(
/*
* We read more chars than allowed. Reset limits to
- * prevent that and try again.
+ * prevent that and try again. Don't forget the extra
+ * padding of TCL_UTF_MAX - 1 bytes demanded by the
+ * Tcl_ExternalToUtf() call!
*/
- dstLimit = Tcl_UtfAtIndex(dst, charsToRead + 1) - dst;
+ dstLimit = Tcl_UtfAtIndex(dst, charsToRead + 1)
+ + TCL_UTF_MAX - 1 - dst;
statePtr->flags = savedFlags;
statePtr->inputEncodingFlags = savedIEFlags;
statePtr->inputEncodingState = savedState;
@@ -6097,8 +6100,12 @@ ReadChars(
consume:
bufPtr->nextRemoved += srcRead;
- if (dstWrote > srcRead + 1) {
- *factorPtr = dstWrote * UTF_EXPANSION_FACTOR / srcRead;
+ /*
+ * If this read contained multibyte characters, revise factorPtr
+ * so the next read will allocate bigger buffers.
+ */
+ if (numChars && numChars < srcRead) {
+ *factorPtr = srcRead * UTF_EXPANSION_FACTOR / numChars;
}
Tcl_SetObjLength(objPtr, numBytes + dstWrote);
return numChars;