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 3db0ca6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 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)) != 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, NULL);
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, NULL);
// Default printer name

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

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

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,8 +766,8 @@ apple_register_profiles(
device_name = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
printer_name = CFStringCreateWithCString(kCFAllocatorDefault,
p->name, kCFStringEncodingUTF8);
printer_name = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
p->name, kCFStringEncodingUTF8, NULL);

if (device_name && printer_name)
{
Expand Down

0 comments on commit 3db0ca6

Please sign in to comment.