diff options
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r-- | generic/tclEncoding.c | 17 |
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; } } |