From bd35e0acad01d4cda8ebad6d6886ec42d9a021fe Mon Sep 17 00:00:00 2001 From: cc_benny Date: Mon, 9 Mar 2009 18:50:49 +0000 Subject: * tkMacOSXFont.c (GetFontFamilyName): [Bug #2548661] Handle NULL return from CFStringCreate. --- ChangeLog | 5 +++++ macosx/tkMacOSXFont.c | 26 ++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 99f3430..1685ab6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-03-09 Benjamin Riefenstahl + + * tkMacOSXFont.c (GetFontFamilyName): [Bug #2548661] Handle NULL + return from CFStringCreate. + 2009-02-27 Jan Nijtmans * doc/GetBitmap.3 [Feature Request 2636558] Tk_DefineBitmap diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index 51d0c4d..eeaef3c 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -35,7 +35,7 @@ * that such fonts can not be used for controls, because controls * definitely require a family id (this assertion needs testing). * - * RCS: @(#) $Id: tkMacOSXFont.c,v 1.43 2008/12/10 05:02:52 das Exp $ + * RCS: @(#) $Id: tkMacOSXFont.c,v 1.44 2009/03/09 18:50:49 cc_benny Exp $ */ #include "tkMacOSXPrivate.h" @@ -2190,7 +2190,9 @@ GetFontFamilyName( /* * QuickDraw font names are encoded with the script that the font uses. - * So we determine that encoding and than we reencode the name. + * So we determine that encoding and than we reencode the name. We + * pre-set the encoding with the default value, so we do not need to + * check result codes here. */ encoding = kTextEncodingMacRoman; @@ -2200,19 +2202,27 @@ GetFontFamilyName( NULL); /* - * Note: We could use Tcl facilities to do the re-encoding here. We'd + * Note: We could use Tcl facilities to do the re-encoding here. We'd * have to maintain tables to map OS encoding codes to Tcl encoding names - * like tkMacOSXFont.c did. Using native re-encoding directly instead is - * a lot easier and future-proof than that. There is one snag, though: I - * have seen CFStringGetCString() crash with invalid encoding ids. But + * like tkMacOSXFont.c did. Using native re-encoding directly instead is + * a lot easier and future-proof than that. There is one snag, though: I + * have seen CFStringGetCString() crash with invalid encoding ids. But * than if that happens it would be a bug in * FMGetFontFamilyTextEncoding() or RevertTextEncodingToScriptInfo(). + * Another problem is that users have seen CFStringCreate return null + * (Bug #2548661). This is due to font names with a bad encoding. */ cfString = CFStringCreateWithPascalStringNoCopy( NULL, nativeName, nameencoding, kCFAllocatorNull); - CFStringGetCString( - cfString, name, numBytes, kCFStringEncodingUTF8); + if (cfString == NULL) { + TkMacOSXDbgMsg("CFStringCreate: " + "'%.*s' could not be decoded with encoding %d", + nativeName[0], nativeName+1, (int) nameencoding); + return kTextMalformedInputErr; + } + + CFStringGetCString(cfString, name, numBytes, kCFStringEncodingUTF8); CFRelease(cfString); return noErr; -- cgit v0.12