Skip to content

Commit

Permalink
Use CFStringCreateWithCStringNoCopy when the CFString doesn't outlast…
Browse files Browse the repository at this point in the history
… the char *

The object is freed before anything happens to the pointers.
  • Loading branch information
AreaZR committed Oct 17, 2024
1 parent 8b6ca61 commit 7b9fc1c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backend/usb-darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ CFStringRef cfstr_create_trim(const char *cstr)
CFStringRef cfstr;
CFMutableStringRef cfmutablestr = NULL;

if ((cfstr = CFStringCreateWithCString(kCFAllocatorDefault, cstr, kCFStringEncodingUTF8)) != NULL)
if ((cfstr = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, cstr, kCFStringEncodingUTF8)) != NULL)
{
if ((cfmutablestr = CFStringCreateMutableCopy(kCFAllocatorDefault, 1024, cfstr)) != NULL)
CFStringTrimWhitespace(cfmutablestr);
Expand Down Expand Up @@ -2071,7 +2071,7 @@ static void setup_cfLanguage(void)
return;
}

lang[0] = CFStringCreateWithCString(kCFAllocatorDefault, requestedLang, kCFStringEncodingUTF8);
lang[0] = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, requestedLang, kCFStringEncodingUTF8);
langArray = CFArrayCreate(kCFAllocatorDefault, (const void **)lang, sizeof(lang) / sizeof(lang[0]), &kCFTypeArrayCallBacks);

CFPreferencesSetValue(CFSTR("AppleLanguages"), langArray, kCFPreferencesCurrentApplication, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
Expand Down
2 changes: 1 addition & 1 deletion cups/dest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ cupsSetDests2(http_t *http, // I - Connection to server or @code CUPS_HTTP_

if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) != NULL)
{
CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, dest->name, kCFStringEncodingUTF8);
CFStringRef name = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, dest->name, kCFStringEncodingUTF8);
// Default printer name

if (name)
Expand Down
8 changes: 4 additions & 4 deletions scheduler/colorman.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ apple_init_profile(
return;
}

cftext = CFStringCreateWithCString(kCFAllocatorDefault, text,
cftext = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, text,
kCFStringEncodingUTF8);

if (cftext)
Expand Down Expand Up @@ -281,9 +281,9 @@ apple_init_profile(

if (attr && attr->text[0])
{
cflang = CFStringCreateWithCString(kCFAllocatorDefault, language,
cflang = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, language,
kCFStringEncodingUTF8);
cftext = CFStringCreateWithCString(kCFAllocatorDefault, attr->text,
cftext = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, attr->text,
kCFStringEncodingUTF8);

if (cflang && cftext)
Expand Down Expand Up @@ -766,7 +766,7 @@ apple_register_profiles(
device_name = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
printer_name = CFStringCreateWithCString(kCFAllocatorDefault,
printer_name = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
p->name, kCFStringEncodingUTF8);

if (device_name && printer_name)
Expand Down

0 comments on commit 7b9fc1c

Please sign in to comment.