From 4b73023b4313e433ded8680d07f1116f98ff1f39 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Mon, 30 Nov 2020 17:02:53 +0100 Subject: [PATCH] - fix app crash with old version of IntelPowerGadget (#202) --- Modules/CPU/readers.swift | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Modules/CPU/readers.swift b/Modules/CPU/readers.swift index ca46c669..958aee32 100644 --- a/Modules/CPU/readers.swift +++ b/Modules/CPU/readers.swift @@ -280,11 +280,26 @@ public class FrequencyReader: Reader { return } - let PG_InitializePointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_Initialize" as CFString) - let PG_ShutdownPointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_Shutdown" as CFString) - let PG_ReadSamplePointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_ReadSample" as CFString) - let PGSample_GetIAFrequencyPointer = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_GetIAFrequency" as CFString) - let PGSample_ReleasePointer = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_Release" as CFString) + guard let PG_InitializePointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_Initialize" as CFString) else { + os_log(.error, log: log, "failed to find PG_Initialize") + return + } + guard let PG_ShutdownPointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_Shutdown" as CFString) else { + os_log(.error, log: log, "failed to find PG_Shutdown") + return + } + guard let PG_ReadSamplePointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_ReadSample" as CFString) else { + os_log(.error, log: log, "failed to find PG_ReadSample") + return + } + guard let PGSample_GetIAFrequencyPointer = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_GetIAFrequency" as CFString) else { + os_log(.error, log: log, "failed to find PGSample_GetIAFrequency") + return + } + guard let PGSample_ReleasePointer = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_Release" as CFString) else { + os_log(.error, log: log, "failed to find PGSample_Release") + return + } let PG_Initialize = unsafeBitCast(PG_InitializePointer, to: PG_InitializePointerFunction.self) self.PG_Shutdown = unsafeBitCast(PG_ShutdownPointer, to: PG_ShutdownPointerFunction.self)