From 6d52fa636f39c421c15a5425a631eba848c27be6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 28 Sep 2026 09:57:45 -0400 Subject: [PATCH] file(READ_MACHO): Avoid crash on unknown archs in this undocumented command `macho_arch_name_for_cpu_type` is implemented by the dynamic loader that ships with the OS, so it can only report architectures that were released at the time that OS was released. It can return `nullptr`. Fixes: #26680 Fixes: #28118 Issue: #28124 --- Source/cmMachO.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/cmMachO.cxx b/Source/cmMachO.cxx index a8a766ff7c..925a321bd1 100644 --- a/Source/cmMachO.cxx +++ b/Source/cmMachO.cxx @@ -375,9 +375,12 @@ cmMachO::StringList cmMachO::GetArchitectures() const char const* archName = "unknown"; #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000 if (__builtin_available(macOS 13.0, *)) { - archName = (header.CpuType & CPU_TYPE_ARM) - ? macho_arch_name_for_cpu_type(header.CpuType, header.CpuSubType) - : macho_arch_name_for_cpu_type(header.CpuType, CPU_SUBTYPE_MULTIPLE); + if (char const* archNameForCpuType = (header.CpuType & CPU_TYPE_ARM) + ? macho_arch_name_for_cpu_type(header.CpuType, header.CpuSubType) + : macho_arch_name_for_cpu_type(header.CpuType, + CPU_SUBTYPE_MULTIPLE)) { + archName = archNameForCpuType; + } } else #endif {