From 24f992668d4072421af7d022ad5015ab3c29d505 Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 13 Mar 2006 20:57:08 +0000 Subject: * generic/tclEncoding.c: Report error when an escape encoding is missing one of its sub-encodings [Bug 506653]. --- ChangeLog | 3 +++ generic/tclEncoding.c | 29 ++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f75ecb..efd6797 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-03-13 Don Porter + * generic/tclEncoding.c: Report error when an escape encoding + is missing one of its sub-encodings [Bug 506653]. + * unix/configure.in: Revert change from 2005-07-26 that sometimes * unix/configure: added $prefix/share to the tcl_pkgPath. See [Patch 1231015]. autoconf-2.13. 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)) { -- cgit v0.12