summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authormdejong <mdejong>2006-12-27 01:25:34 (GMT)
committermdejong <mdejong>2006-12-27 01:25:34 (GMT)
commitdd7cd48fab975a8f107a92c4af405aed06740beb (patch)
treeb8bf3a0b85d06dc14185e6634631567e10867c91 /generic
parent646153ee6f2578dcc60f01bd190d774ff3e6ef63 (diff)
downloadtcl-dd7cd48fab975a8f107a92c4af405aed06740beb.zip
tcl-dd7cd48fab975a8f107a92c4af405aed06740beb.tar.gz
tcl-dd7cd48fab975a8f107a92c4af405aed06740beb.tar.bz2
* generic/tclEncoding.c (EscapeFromUtfProc):
Clear the TCL_ENCODING_END flag when end bytes are written. This fix keep this method from writing escape bytes for an encoding like iso2022-jp multiple times when the escape byte overlap with the end of the IO buffer. * tests/io.test: Add test for escape byte overlap issue.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclEncoding.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index 69c7f28..11c838a 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclEncoding.c,v 1.51 2006/11/13 08:23:07 das Exp $
+ * RCS: @(#) $Id: tclEncoding.c,v 1.52 2006/12/27 01:25:35 mdejong Exp $
*/
#include "tclInt.h"
@@ -2981,7 +2981,7 @@ EscapeFromUtfProc(
if (flags & TCL_ENCODING_START) {
state = 0;
- if (dst + dataPtr->initLen > dstEnd) {
+ if ((dst + dataPtr->initLen) > dstEnd) {
*srcReadPtr = 0;
*dstWrotePtr = 0;
return TCL_CONVERT_NOSPACE;
@@ -3089,7 +3089,17 @@ EscapeFromUtfProc(
if ((result == TCL_OK) && (flags & TCL_ENCODING_END)) {
unsigned int len = dataPtr->subTables[0].sequenceLen;
- if (dst + dataPtr->finalLen + (state?len:0) > dstEnd) {
+ /*
+ * Certain encodings like iso2022-jp need to write
+ * an escape sequence after all characters have
+ * been converted. This logic checks that enough
+ * room is available in the buffer for the escape bytes.
+ * The TCL_ENCODING_END flag is cleared after a final
+ * escape sequence has been added to the buffer so
+ * that another call to this method does not attempt
+ * to append escape bytes a second time.
+ */
+ if ((dst + dataPtr->finalLen + (state?len:0)) > dstEnd) {
result = TCL_CONVERT_NOSPACE;
} else {
if (state) {
@@ -3100,6 +3110,7 @@ EscapeFromUtfProc(
memcpy((VOID *) dst, (VOID *) dataPtr->final,
(size_t) dataPtr->finalLen);
dst += dataPtr->finalLen;
+ state &= ~TCL_ENCODING_END;
}
}