I'm trying to create a new CFStringRef
from a const char*
at runtime, but CFStringCreateWithCString
returns null
for all strings shorter than 10 characters:
// Test w/ 9-character string
CFStringRef str1 = CFStringCreateWithCString(NULL, "123456789", kCFStringEncodingUTF8);
printf("str1: %p - %s\n", str1, CFStringGetCStringPtr(str1, kCFStringEncodingUTF8));
// Test w/ 10-character string
CFStringRef str2 = CFStringCreateWithCString(NULL, "0123456789", kCFStringEncodingUTF8);
printf("str2: %p - %s\n", str2, CFStringGetCStringPtr(str2, kCFStringEncodingUTF8));
Output of above example:
str1: 0x1ea1f72bb30ab195 - (null)
str2: 0x1005073e0 - 0123456789
As you can see, the first string (consisting of 9 characters) returns null
, while the second one (10 characters) works fine.
I made some tests and it seems like CFStringCreateWithCString
works fine for all strings with more than 10 characters, but always returns null
for strings with 9 or less.
What could cause this behavior and how can I fix it?