From 6eed4898468c0fae5a6e2d0ab0bb6954723a356f Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Fri, 5 Apr 2024 19:13:59 +0200 Subject: Use size_t for array indices consistently This avoids a compiler warning with GCC 14 and LTO claiming uninitialized use of data[i] in the last loop. --- linux/LibSensors.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/linux/LibSensors.c b/linux/LibSensors.c index 53734161..bfc5903b 100644 --- a/linux/LibSensors.c +++ b/linux/LibSensors.c @@ -230,7 +230,7 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns /* Only package temperature - copy to all cores */ if (coreTempCount == 0 && !isNaN(data[0])) { - for (unsigned int i = 1; i <= existingCPUs; i++) + for (size_t i = 1; i <= existingCPUs; i++) data[i] = data[0]; /* No further adjustments */ @@ -240,7 +240,7 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns /* No package temperature - set to max core temperature */ if (coreTempCount > 0 && isNaN(data[0])) { double maxTemp = -HUGE_VAL; - for (unsigned int i = 1; i <= existingCPUs; i++) { + for (size_t i = 1; i <= existingCPUs; i++) { if (isgreater(data[i], maxTemp)) { maxTemp = data[i]; data[0] = data[i]; @@ -252,7 +252,7 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns /* Only temperature for core 0, maybe Ryzen - copy to all other cores */ if (coreTempCount == 1 && !isNaN(data[1])) { - for (unsigned int i = 2; i <= existingCPUs; i++) + for (size_t i = 2; i <= existingCPUs; i++) data[i] = data[1]; /* No further adjustments */ @@ -260,7 +260,7 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns } /* Half the temperatures, probably HT/SMT - copy to second half */ - const unsigned int delta = activeCPUs / 2; + const size_t delta = activeCPUs / 2; if (coreTempCount == delta) { memcpy(&data[delta + 1], &data[1], delta * sizeof(*data)); @@ -269,7 +269,7 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns } out: - for (unsigned int i = 0; i <= existingCPUs; i++) + for (size_t i = 0; i <= existingCPUs; i++) cpus[i].temperature = data[i]; free(data); -- cgit v1.2.3