Fix possinble division by zero in cputemp.go
This commit is contained in:
@@ -23,6 +23,7 @@ func (c *MyConfig) UpdateCPUTemperature() {
|
||||
temperature = make([]int64, n)
|
||||
tSum int64
|
||||
tAvg int64
|
||||
validCount int
|
||||
)
|
||||
|
||||
if Delay == InitialDelay {
|
||||
@@ -62,20 +63,30 @@ func (c *MyConfig) UpdateCPUTemperature() {
|
||||
}
|
||||
|
||||
temperature[i] = temp
|
||||
validCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(temperature) == 1 {
|
||||
tAvg = temperature[0]
|
||||
if validCount == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if validCount == 1 {
|
||||
for _, t := range temperature {
|
||||
if t != 0 {
|
||||
tAvg = t
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, t := range temperature {
|
||||
tSum += t
|
||||
}
|
||||
|
||||
tAvg = tSum / int64(len(temperature))
|
||||
tAvg = tSum / int64(validCount)
|
||||
}
|
||||
|
||||
if c.Values.CPUTemperature != tAvg {
|
||||
|
||||
Reference in New Issue
Block a user