summaryrefslogtreecommitdiffstats
path: root/src/osx/smc.cpp
diff options
context:
space:
mode:
authorJos Dehaes <jos.dehaes@gmail.com>2023-08-23 15:46:47 +0200
committerJos Dehaes <jos.dehaes@gmail.com>2023-08-23 15:46:47 +0200
commitdcbdb7360d44b4071ec0fe0757a0875a12147c8a (patch)
tree381870337ffd765e3124227eb01871023ba3b055 /src/osx/smc.cpp
parent1b126f55e38de76a2cca796593ef1554828d61e6 (diff)
[macos] fix temp sensor on system with many cores
Diffstat (limited to 'src/osx/smc.cpp')
-rw-r--r--src/osx/smc.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/osx/smc.cpp b/src/osx/smc.cpp
index 95d75f0..ace9ce6 100644
--- a/src/osx/smc.cpp
+++ b/src/osx/smc.cpp
@@ -18,6 +18,9 @@ tab-size = 4
#include "smc.hpp"
+static constexpr size_t MaxIndexCount = sizeof("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") - 1;
+static constexpr const char *KeyIndexes = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
static UInt32 _strtoul(char *str, int size, int base) {
UInt32 total = 0;
int i;
@@ -91,13 +94,16 @@ namespace Cpu {
// according to VirtualSMC docs (hackintosh fake SMC) the enumeration follows with alphabetic chars - not implemented yet here (nor in VirtualSMC)
long long SMCConnection::getTemp(int core) {
char key[] = SMC_KEY_CPU_TEMP;
+ if (core > MaxIndexCount) {
+ return -1;
+ }
if (core >= 0) {
- snprintf(key, 5, "TC%1dc", core);
+ snprintf(key, 5, "TC%1cc", KeyIndexes[core]);
}
long long result = getSMCTemp(key);
if (result == -1) {
// try again with C
- snprintf(key, 5, "TC%1dC", core);
+ snprintf(key, 5, "TC%1dC", KeyIndexes[core]);
result = getSMCTemp(key);
}
return result;