From aa694753fda0660d285d2a20101c69500c6e77d4 Mon Sep 17 00:00:00 2001 From: npyl Date: Sun, 29 Jul 2018 16:49:19 +0300 Subject: [PATCH] Some improvements for get_freq again. Fix frequency not printing correctly (I wasn't using the divisor) Add more guards. --- src/darwin.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/darwin.cc b/src/darwin.cc index 2a501e7b9..d66498609 100644 --- a/src/darwin.cc +++ b/src/darwin.cc @@ -973,6 +973,12 @@ void get_acpi_fan(char * /*p_client_buffer*/, size_t /*client_buffer_size*/) { /* void */ char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_format, int divisor, unsigned int cpu) { + + if ((p_client_buffer == nullptr) || client_buffer_size <= 0 || + (p_format == nullptr) || divisor <= 0) { + return 0; + } + #ifdef BUILD_IPGFREQ /* * Our data is always the same for every core, so ignore |cpu| argument. @@ -980,8 +986,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, static bool initialised = false; - if (!initialised) - { + if (!initialised) { IntelEnergyLibInitialize(); initialised = true; } @@ -990,7 +995,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, GetIAFrequency(cpu, &freq); snprintf(p_client_buffer, client_buffer_size, p_format, - static_cast(freq)); + static_cast(freq) / divisor); #else /* * We get the factory cpu frequency, not **current** cpu frequency @@ -1002,11 +1007,6 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, unsigned int freq; size_t len; - if ((p_client_buffer == nullptr) || client_buffer_size <= 0 || - (p_format == nullptr) || divisor <= 0) { - return 0; - } - mib[0] = CTL_HW; mib[1] = HW_CPU_FREQ; len = sizeof(freq); @@ -1024,7 +1024,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, return 0; } #endif - + return 1; }