From 42de1edc225f504458e1cc7a3550ccd97054be52 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sun, 6 Mar 2022 15:45:17 +0000 Subject: [PATCH] Rework cpu freq node handling Similar to the prior commit - fscanf directly into the required data type. Signed-off-by: Emil Velikov --- src/cpu.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cpu.cpp b/src/cpu.cpp index 7fde0c75..fabf651a 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -227,13 +227,14 @@ bool CPUStats::UpdateCPUData() bool CPUStats::UpdateCoreMhz() { m_coreMhz.clear(); FILE *fp; - char str[10]; for (size_t i = 0; i < m_cpuData.size(); i++) { std::string path = "/sys/devices/system/cpu/cpu" + std::to_string(i) + "/cpufreq/scaling_cur_freq"; if ((fp = fopen(path.c_str(), "r"))){ - fscanf(fp, "%s", str); - m_cpuData[i].mhz = atoi(str) / 1000; + int64_t temp; + if (fscanf(fp, "%" PRId64, &temp) != 1) + temp = 0; + m_cpuData[i].mhz = temp / 1000; fclose(fp); } }