Skip to content

Commit e60b9f6

Browse files
committed
Util (macOS): cleanup cf_helpers.c
1 parent d7fa041 commit e60b9f6

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/util/apple/cf_helpers.c

+5-10
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,17 @@ const char* ffCfStrGetString(CFTypeRef cf, FFstrbuf* result)
5252

5353
const char* cstr = CFStringGetCStringPtr(cfStr, kCFStringEncodingUTF8);
5454
if (cstr)
55-
{
5655
ffStrbufSetS(result, cstr);
57-
return NULL;
58-
}
5956
else
6057
{
61-
uint32_t length = CFStringGetLength(cfStr);
62-
uint32_t maxLength = (uint32_t) CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
63-
ffStrbufEnsureFixedLengthFree(result, maxLength);
58+
uint32_t length = (uint32_t) CFStringGetLength(cfStr);
59+
ffStrbufEnsureFixedLengthFree(result, CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8));
6460
if(!CFStringGetCString(cfStr, result->chars, result->allocated, kCFStringEncodingUTF8))
6561
return "CFStringGetCString() failed";
62+
// CFStringGetCString ensures the buffer is NUL terminated
63+
// https://developer.apple.com/documentation/corefoundation/1542721-cfstringgetcstring
64+
result->length = (uint32_t) strnlen(result->chars, (uint32_t)result->allocated);
6665
}
67-
68-
// CFStringGetCString ensures the buffer is NUL terminated
69-
// https://developer.apple.com/documentation/corefoundation/1542721-cfstringgetcstring
70-
result->length = (uint32_t) strnlen(result->chars, (uint32_t)result->allocated);
7166
}
7267
else if (CFGetTypeID(cf) == CFDataGetTypeID())
7368
{

0 commit comments

Comments
 (0)