summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcc_benny <cc_benny>2009-03-09 18:50:49 (GMT)
committercc_benny <cc_benny>2009-03-09 18:50:49 (GMT)
commitbd35e0acad01d4cda8ebad6d6886ec42d9a021fe (patch)
treef8d5eef4a0cd5ad1e762bad0e2d8299e810fc2b0
parentdcd56d8fd6bddfd1ef90d40da1df64202c8de229 (diff)
downloadtk-bd35e0acad01d4cda8ebad6d6886ec42d9a021fe.zip
tk-bd35e0acad01d4cda8ebad6d6886ec42d9a021fe.tar.gz
tk-bd35e0acad01d4cda8ebad6d6886ec42d9a021fe.tar.bz2
* tkMacOSXFont.c (GetFontFamilyName): [Bug #2548661] Handle
NULL return from CFStringCreate.
-rw-r--r--ChangeLog5
-rw-r--r--macosx/tkMacOSXFont.c26
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 <b.riefenstahl@turtle-trading.net>
+
+ * tkMacOSXFont.c (GetFontFamilyName): [Bug #2548661] Handle NULL
+ return from CFStringCreate.
+
2009-02-27 Jan Nijtmans <nijtmans@users.sf.net>
* 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;