diff options
author | donal.k.fellows@manchester.ac.uk <dkf> | 2006-04-25 08:29:36 (GMT) |
---|---|---|
committer | donal.k.fellows@manchester.ac.uk <dkf> | 2006-04-25 08:29:36 (GMT) |
commit | fb1dd7d7db4f17aa2f7d203c90974bc6b0b983e0 (patch) | |
tree | e517a54cd20a4fec721d021592e16aacac4e30ba /unix/tkUnixFont.c | |
parent | 933ce33791568d122978bfd1d6514537851ba148 (diff) | |
download | tk-fb1dd7d7db4f17aa2f7d203c90974bc6b0b983e0.zip tk-fb1dd7d7db4f17aa2f7d203c90974bc6b0b983e0.tar.gz tk-fb1dd7d7db4f17aa2f7d203c90974bc6b0b983e0.tar.bz2 |
Fix problems caused when XServer returns invalid font names. [Bug 1475865]
Diffstat (limited to 'unix/tkUnixFont.c')
-rw-r--r-- | unix/tkUnixFont.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/unix/tkUnixFont.c b/unix/tkUnixFont.c index 1de1b1f..66f8550 100644 --- a/unix/tkUnixFont.c +++ b/unix/tkUnixFont.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkUnixFont.c,v 1.18.2.4 2005/04/12 22:05:47 hobbs Exp $ + * RCS: @(#) $Id: tkUnixFont.c,v 1.18.2.5 2006/04/25 08:29:36 dkf Exp $ */ #include "tkUnixInt.h" @@ -850,8 +850,26 @@ TkpGetFontFamilies(interp, tkwin) Tcl_InitHashTable(&familyTable, TCL_STRING_KEYS); nameList = ListFonts(Tk_Display(tkwin), "*", &numNames); for (i = 0; i < numNames; i++) { + char *familyEnd; + + family = strchr(nameList[i] + 1, '-'); + if (family == NULL) { + /* + * Apparently, sometimes ListFonts() can return a font name with + * zero or one '-' character in it. This is probably indicative of + * a server misconfiguration, but crashing because of it is a very + * bad idea anyway. [Bug 1475865] + */ + + continue; + } + family++; /* Advance to char after '-'. */ + familyEnd = strchr(family, '-'); + if (familyEnd == NULL) { + continue; /* See comment above. */ + } + *familyEnd = '\0'; family = strchr(nameList[i] + 1, '-') + 1; - strchr(family, '-')[0] = '\0'; Tcl_CreateHashEntry(&familyTable, family, &new); } XFreeFontNames(nameList); |