diff options
author | cc_benny <cc_benny@noemail.net> | 2009-03-09 18:50:48 (GMT) |
---|---|---|
committer | cc_benny <cc_benny@noemail.net> | 2009-03-09 18:50:48 (GMT) |
commit | a032025de2b5545da1b0062476d55ece64b75d19 (patch) | |
tree | f8d5eef4a0cd5ad1e762bad0e2d8299e810fc2b0 /macosx | |
parent | 91d34a14fd46e125420ed21d4958855372f5799c (diff) | |
download | tk-a032025de2b5545da1b0062476d55ece64b75d19.zip tk-a032025de2b5545da1b0062476d55ece64b75d19.tar.gz tk-a032025de2b5545da1b0062476d55ece64b75d19.tar.bz2 |
* tkMacOSXFont.c (GetFontFamilyName): [Bug #2548661] Handle
NULL return from CFStringCreate.
FossilOrigin-Name: 715b7194f2bed52f4e1888b8d23fe07e608e7261
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXFont.c | 26 |
1 files changed, 18 insertions, 8 deletions
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; |