diff options
author | dgp <dgp@users.sourceforge.net> | 2006-03-13 20:57:08 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2006-03-13 20:57:08 (GMT) |
commit | 24f992668d4072421af7d022ad5015ab3c29d505 (patch) | |
tree | 1c9cc9aee68f90a783fa0a732098ddb16fe08f1c /generic/tclEncoding.c | |
parent | e96cb5c2cb64528117d94b92570a994523851d29 (diff) | |
download | tcl-24f992668d4072421af7d022ad5015ab3c29d505.zip tcl-24f992668d4072421af7d022ad5015ab3c29d505.tar.gz tcl-24f992668d4072421af7d022ad5015ab3c29d505.tar.bz2 |
* generic/tclEncoding.c: Report error when an escape encoding
is missing one of its sub-encodings [Bug 506653].
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r-- | generic/tclEncoding.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 6a8ae6e..5fa799e 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.16.2.8 2005/10/05 04:27:38 hobbs Exp $ + * RCS: @(#) $Id: tclEncoding.c,v 1.16.2.9 2006/03/13 20:57:09 dgp Exp $ */ #include "tclInt.h" @@ -1355,6 +1355,9 @@ LoadEncodingFile(interp, name) } if ((encoding == NULL) && (interp != NULL)) { Tcl_AppendResult(interp, "invalid encoding file \"", name, "\"", NULL); + if (ch == 'E') { + Tcl_AppendResult(interp, " or missing sub-encoding", NULL); + } } Tcl_Close(NULL, chan); return encoding; @@ -1722,7 +1725,7 @@ LoadEscapeEncoding(name, chan) CONST char *name; /* Name for new encoding. */ Tcl_Channel chan; /* File containing new encoding. */ { - int i; + int i, missingSubEncoding = 0; unsigned int size; Tcl_DString escapeData; char init[16], final[16]; @@ -1766,16 +1769,27 @@ LoadEscapeEncoding(name, chan) strncpy(est.name, argv[0], sizeof(est.name)); est.name[sizeof(est.name) - 1] = '\0'; - /* To avoid infinite recursion in [encoding system iso2022-*]*/ - Tcl_GetEncoding(NULL, est.name); + /* + * Load the subencodings first so we're never stuck + * trying to use a half-loaded system encoding to + * open/read a *.enc file. + */ - est.encodingPtr = NULL; + est.encodingPtr = (Encoding *) Tcl_GetEncoding(NULL, est.name); + if ((est.encodingPtr == NULL) + || (est.encodingPtr->toUtfProc != TableToUtfProc)) { + missingSubEncoding = 1; + } Tcl_DStringAppend(&escapeData, (char *) &est, sizeof(est)); } } ckfree((char *) argv); Tcl_DStringFree(&lineString); } + if (missingSubEncoding) { + Tcl_DStringFree(&escapeData); + return NULL; + } size = sizeof(EscapeEncodingData) - sizeof(EscapeSubTable) + Tcl_DStringLength(&escapeData); @@ -2997,6 +3011,11 @@ GetTableEncoding(dataPtr, state) subTablePtr = &dataPtr->subTables[state]; encodingPtr = subTablePtr->encodingPtr; if (encodingPtr == NULL) { + /* + * Now that escape encodings load their sub-encodings first, and + * fail to load if any sub-encodings are missing, this branch should + * never happen. + */ encodingPtr = (Encoding *) Tcl_GetEncoding(NULL, subTablePtr->name); if ((encodingPtr == NULL) || (encodingPtr->toUtfProc != TableToUtfProc)) { |