summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2002-03-04 22:00:38 (GMT)
committerhobbs <hobbs>2002-03-04 22:00:38 (GMT)
commit5a598af441f3863e58e7d6f31cb56421774d59a6 (patch)
treec77eaa3f737bd87747c287a7ad6f6a2770bcc2d6 /generic/tclEncoding.c
parent1c18b5b6965b64591b52b118d863cb8e109fb8a1 (diff)
downloadtcl-5a598af441f3863e58e7d6f31cb56421774d59a6.zip
tcl-5a598af441f3863e58e7d6f31cb56421774d59a6.tar.gz
tcl-5a598af441f3863e58e7d6f31cb56421774d59a6.tar.bz2
* tests/io.test:
* tests/encoding.test: corrected iso2022 encoding results. added encoding-24.* * generic/tclEncoding.c (EscapeFromUtfProc): corrected output of escape codes as per RFC 1468. [Patch #474358] (taguchi) (TclFinalizeEncodingSubsystem): corrected potential double-free when encodings were finalized on exit. [Bug #219314, #524674]
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index c42d899..b974e04 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.10 2002/02/08 02:52:54 dgp Exp $
+ * RCS: @(#) $Id: tclEncoding.c,v 1.11 2002/03/04 22:00:39 hobbs Exp $
*/
#include "tclInt.h"
@@ -310,18 +310,16 @@ TclFinalizeEncodingSubsystem()
{
Tcl_HashSearch search;
Tcl_HashEntry *hPtr;
- Encoding *encodingPtr;
Tcl_MutexLock(&encodingMutex);
encodingsInitialized = 0;
hPtr = Tcl_FirstHashEntry(&encodingTable, &search);
while (hPtr != NULL) {
- encodingPtr = (Encoding *) Tcl_GetHashValue(hPtr);
- if (encodingPtr->freeProc != NULL) {
- (*encodingPtr->freeProc)(encodingPtr->clientData);
- }
- ckfree((char *) encodingPtr->name);
- ckfree((char *) encodingPtr);
+ /*
+ * Call FreeEncoding instead of doing it directly to handle refcounts
+ * like escape encodings use. [Bug #524674]
+ */
+ FreeEncoding((Tcl_Encoding) Tcl_GetHashValue(hPtr));
hPtr = Tcl_NextHashEntry(&search);
}
Tcl_DeleteHashTable(&encodingTable);
@@ -2206,6 +2204,10 @@ TableFreeProc(clientData)
{
TableEncodingData *dataPtr;
+ /*
+ * Make sure we aren't freeing twice on shutdown. [Bug #219314]
+ */
+
dataPtr = (TableEncodingData *) clientData;
ckfree((char *) dataPtr->toUnicode);
ckfree((char *) dataPtr->fromUnicode);
@@ -2491,12 +2493,14 @@ EscapeFromUtfProc(clientData, src, srcLen, flags, statePtr, dst, dstLen,
dstStart = dst;
dstEnd = dst + dstLen - 1;
+ /*
+ * RFC1468 states that the text starts in ASCII, and switches to Japanese
+ * characters, and that the text must end in ASCII. [Patch #474358]
+ */
+
if (flags & TCL_ENCODING_START) {
- unsigned int len;
-
state = 0;
- len = dataPtr->subTables[0].sequenceLen;
- if (dst + dataPtr->initLen + len > dstEnd) {
+ if (dst + dataPtr->initLen > dstEnd) {
*srcReadPtr = 0;
*dstWrotePtr = 0;
return TCL_CONVERT_NOSPACE;
@@ -2504,9 +2508,6 @@ EscapeFromUtfProc(clientData, src, srcLen, flags, statePtr, dst, dstLen,
memcpy((VOID *) dst, (VOID *) dataPtr->init,
(size_t) dataPtr->initLen);
dst += dataPtr->initLen;
- memcpy((VOID *) dst, (VOID *) dataPtr->subTables[0].sequence,
- (size_t) len);
- dst += len;
} else {
state = (int) *statePtr;
}
@@ -2591,9 +2592,15 @@ EscapeFromUtfProc(clientData, src, srcLen, flags, statePtr, dst, dstLen,
}
if ((result == TCL_OK) && (flags & TCL_ENCODING_END)) {
- if (dst + dataPtr->finalLen > dstEnd) {
+ unsigned int len = dataPtr->subTables[0].sequenceLen;
+ if (dst + dataPtr->finalLen + (state?len:0) > dstEnd) {
result = TCL_CONVERT_NOSPACE;
} else {
+ if (state) {
+ memcpy((VOID *) dst, (VOID *) dataPtr->subTables[0].sequence,
+ (size_t) len);
+ dst += len;
+ }
memcpy((VOID *) dst, (VOID *) dataPtr->final,
(size_t) dataPtr->finalLen);
dst += dataPtr->finalLen;