summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2002-04-18 01:51:20 (GMT)
committerhobbs <hobbs>2002-04-18 01:51:20 (GMT)
commit342091a852b8bbb1cf9351963ac23d540938fc5e (patch)
tree67154089cf51615a947e6c14f7354e2666b920ae /generic/tclEncoding.c
parentf5cdd166444167dcff3596e1b2d41059daf7654d (diff)
downloadtcl-342091a852b8bbb1cf9351963ac23d540938fc5e.zip
tcl-342091a852b8bbb1cf9351963ac23d540938fc5e.tar.gz
tcl-342091a852b8bbb1cf9351963ac23d540938fc5e.tar.bz2
* generic/tclEncoding.c (EscapeFromUtfProc):
* generic/tclIO.c (WriteChars, Tcl_Close): corrected the handling of outputting end escapes for escape-based encodings. [Bug #526524] (yamamoto)
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index b61c92d..ca5bacf 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.12 2002/03/11 20:43:07 mdejong Exp $
+ * RCS: @(#) $Id: tclEncoding.c,v 1.13 2002/04/18 01:51:20 hobbs Exp $
*/
#include "tclInt.h"
@@ -2562,14 +2562,28 @@ EscapeFromUtfProc(clientData, src, srcLen, flags, statePtr, dst, dstLen,
tablePrefixBytes = tableDataPtr->prefixBytes;
tableFromUnicode = tableDataPtr->fromUnicode;
- subTablePtr = &dataPtr->subTables[state];
- if (dst + subTablePtr->sequenceLen > dstEnd) {
- result = TCL_CONVERT_NOSPACE;
- break;
+ /*
+ * The state variable has the value of oldState when word is 0.
+ * In this case, the escape sequense should not be copied to dst
+ * because the current character set is not changed.
+ */
+ if (state != oldState) {
+ subTablePtr = &dataPtr->subTables[state];
+ if ((dst + subTablePtr->sequenceLen) > dstEnd) {
+ /*
+ * If there is no space to write the escape sequence, the
+ * state variable must be changed to the value of oldState
+ * variable because this escape sequence must be written
+ * in the next conversion.
+ */
+ state = oldState;
+ result = TCL_CONVERT_NOSPACE;
+ break;
+ }
+ memcpy((VOID *) dst, (VOID *) subTablePtr->sequence,
+ (size_t) subTablePtr->sequenceLen);
+ dst += subTablePtr->sequenceLen;
}
- memcpy((VOID *) dst, (VOID *) subTablePtr->sequence,
- (size_t) subTablePtr->sequenceLen);
- dst += subTablePtr->sequenceLen;
}
if (tablePrefixBytes[(word >> 8)] != 0) {