Commit 83535f02 authored by Marvin Scholz's avatar Marvin Scholz

freetype: Fix copying char buffer of CStringRef on darwin

To convert a CStringRef to a char buffer, CFStringGetCStringPtr was
used, but the documentation states this can fail in some
circumstances and it does fail on 10.7 for example.

This commit fixes this by adding a helper function, which falls back to
CFStringGetCString, as suggested in the CFStringGetCStringPtr docs.
parent c4735712
......@@ -42,15 +42,32 @@
char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor);
void addNewFontToFamily(filter_t *p_filter, CTFontDescriptorRef iter, char *path, vlc_family_t *family);
static char* getCStringCopyForCFStringRef(CFStringRef cfstring, CFStringEncoding encoding)
// Try to get pointer directly
const char *cptr = CFStringGetCStringPtr(cfstring, encoding);
if (cptr) {
return strdup(cptr);
// If it fails, use CFStringGetCString
CFIndex len = CFStringGetLength(cfstring);
CFIndex size = CFStringGetMaximumSizeForEncoding(len, encoding);
char *buffer = calloc(len + 1, sizeof(char));
if (CFStringGetCString(cfstring, buffer, size, encoding)) {
return buffer;
} else {
return NULL;
char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor)
CFURLRef url = CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontURLAttribute);
CFStringRef path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
char *cpath = (char *)CFStringGetCStringPtr(path, kCFStringEncodingUTF8);
char *retPath = NULL;
if (cpath) {
retPath = strdup(cpath);
char *retPath = getCStringCopyForCFStringRef(path, kCFStringEncodingUTF8);
return retPath;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment