Skip to content

Commit d69251d

Browse files
committed
cocoa: fix UTF8String misuse + move AVFoundation link to HAVE_MICROPHONE
Two issues on the PPC/Leopard make build: cocoa_common.m:1062: warning: passing argument 1 of 'config_file_new_from_string' discards qualifiers from pointer target type ld: framework not found AVFoundation ISSUE 1: config_file_new_from_string() takes (char*) and the header explicitly documents that it mutates its input in place. -[NSString UTF8String] returns an Apple-owned buffer that is not writable. Passing it through directly is undefined behavior, not merely a qualifier warning - modern Obj-C with tagged-pointer string optimizations may crash or corrupt other strings. Follow the pattern already used at tasks/task_autodetect.c:374: strdup() the UTF-8 copy, pass the duplicate, free() it after. This fix matters on every platform, not just PPC. ISSUE 2: AVFoundation is 10.7+ and doesn't exist on the 10.5 SDK. Makefile.common linked it unconditionally whenever HAVE_COREAUDIO was set, even though the base coreaudio.c path doesn't use it; only coreaudio_mic_macos.m does. HAVE_MICROPHONE was already auto- disabled on pre-10.7 by c11279c, so the AVFoundation link is unnecessary on those targets and breaks the build. Move '-framework AVFoundation' into the ifeq ($(HAVE_MICROPHONE), 1) block. Modern builds with microphone support still link it; pre-10.7 builds (microphone auto-disabled) skip it. Accelerate and AudioToolbox stay in the outer block - both are 10.3+ and always needed when coreaudio is built.
1 parent f4d1390 commit d69251d

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

Makefile.common

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,14 @@ ifeq ($(HAVE_COREAUDIO), 1)
814814
OBJ += audio/drivers/coreaudio.o
815815
ifeq ($(HAVE_MICROPHONE), 1)
816816
OBJ += audio/drivers/coreaudio_mic_macos.o
817+
# AVFoundation is 10.7+ and only needed by the microphone driver.
818+
# The base coreaudio.c path doesn't use it, so keep it out of the
819+
# link line on targets without microphone support (e.g. pre-10.7
820+
# / Tiger / Leopard / PowerPC).
821+
LIBS += -framework AVFoundation
817822
endif
818823
HAVE_COREAUDIO_LIBS = 1
819-
LIBS += -framework AudioToolbox -framework AVFoundation -framework Accelerate
824+
LIBS += -framework AudioToolbox -framework Accelerate
820825
endif
821826

822827
ifeq ($(HAVE_COREAUDIO3), 1)

ui/drivers/cocoa/cocoa_common.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,8 +1059,17 @@ bool cocoa_get_metrics(
10591059
NSString *backup = [[NSUserDefaults standardUserDefaults] stringForKey:@FILE_PATH_MAIN_CONFIG];
10601060
if ([backup length] > 0)
10611061
{
1062-
conf = config_file_new_from_string([backup UTF8String], path_get(RARCH_PATH_CONFIG));
1063-
config_set_int(conf, "bundle_assets_extract_last_version", 0);
1062+
/* config_file_new_from_string() takes (char*) and mutates it in
1063+
* place. -[NSString UTF8String] returns an Apple-owned buffer
1064+
* that is not writable, so we must strdup() first and free
1065+
* after. */
1066+
char *backup_copy = strdup([backup UTF8String]);
1067+
if (backup_copy)
1068+
{
1069+
conf = config_file_new_from_string(backup_copy, path_get(RARCH_PATH_CONFIG));
1070+
config_set_int(conf, "bundle_assets_extract_last_version", 0);
1071+
free(backup_copy);
1072+
}
10641073
}
10651074
return conf;
10661075
}

0 commit comments

Comments
 (0)