11#include "cfdict_helpers.h"
22
3- bool ffCfDictGetString (CFMutableDictionaryRef dict , CFStringRef key , FFstrbuf * result )
3+ bool ffCfDictGetString (CFDictionaryRef dict , CFStringRef key , FFstrbuf * result )
44{
55 CFTypeRef cf = (CFTypeRef )CFDictionaryGetValue (dict , key );
66 if (cf == NULL )
@@ -10,12 +10,13 @@ bool ffCfDictGetString(CFMutableDictionaryRef dict, CFStringRef key, FFstrbuf* r
1010 {
1111 CFStringRef cfStr = (CFStringRef )cf ;
1212 uint32_t length = (uint32_t )CFStringGetLength (cfStr );
13- ffStrbufEnsureFree (result , length + 1 );
14- if (CFStringGetCString (cfStr , result -> chars , length + 1 , kCFStringEncodingASCII ))
13+ //CFString stores UTF16 characters, therefore may require larger buffer to convert to UTF8 string
14+ ffStrbufEnsureFree (result , length * 2 );
15+ if (CFStringGetCString (cfStr , result -> chars , result -> allocated , kCFStringEncodingUTF8 ))
1516 {
16- result -> length = length ;
1717 // CFStringGetCString ensures the buffer is NUL terminated
1818 // https://developer.apple.com/documentation/corefoundation/1542721-cfstringgetcstring
19+ result -> length = strnlen (result -> chars , (uint32_t )result -> allocated );
1920 }
2021 }
2122 else if (CFGetTypeID (cf ) == CFDataGetTypeID ())
@@ -34,7 +35,7 @@ bool ffCfDictGetString(CFMutableDictionaryRef dict, CFStringRef key, FFstrbuf* r
3435 return true;
3536}
3637
37- bool ffCfDictGetBool (CFMutableDictionaryRef dict , CFStringRef key , bool * result )
38+ bool ffCfDictGetBool (CFDictionaryRef dict , CFStringRef key , bool * result )
3839{
3940 CFBooleanRef cf = (CFBooleanRef )CFDictionaryGetValue (dict , key );
4041 if (cf == NULL || CFGetTypeID (cf ) != CFBooleanGetTypeID ())
@@ -44,7 +45,7 @@ bool ffCfDictGetBool(CFMutableDictionaryRef dict, CFStringRef key, bool* result)
4445 return true;
4546}
4647
47- bool ffCfDictGetInt (CFMutableDictionaryRef dict , CFStringRef key , int * result )
48+ bool ffCfDictGetInt (CFDictionaryRef dict , CFStringRef key , int * result )
4849{
4950 CFNumberRef cf = (CFNumberRef )CFDictionaryGetValue (dict , key );
5051 if (cf == NULL || CFGetTypeID (cf ) != CFNumberGetTypeID ())
0 commit comments