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)
|
temperature = make([]int64, n)
|
||||||
tSum int64
|
tSum int64
|
||||||
tAvg int64
|
tAvg int64
|
||||||
|
validCount int
|
||||||
)
|
)
|
||||||
|
|
||||||
if Delay == InitialDelay {
|
if Delay == InitialDelay {
|
||||||
@@ -62,20 +63,30 @@ func (c *MyConfig) UpdateCPUTemperature() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
temperature[i] = temp
|
temperature[i] = temp
|
||||||
|
validCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(temperature) == 1 {
|
if validCount == 0 {
|
||||||
tAvg = temperature[0]
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if validCount == 1 {
|
||||||
|
for _, t := range temperature {
|
||||||
|
if t != 0 {
|
||||||
|
tAvg = t
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, t := range temperature {
|
for _, t := range temperature {
|
||||||
tSum += t
|
tSum += t
|
||||||
}
|
}
|
||||||
|
|
||||||
tAvg = tSum / int64(len(temperature))
|
tAvg = tSum / int64(validCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Values.CPUTemperature != tAvg {
|
if c.Values.CPUTemperature != tAvg {
|
||||||
|
|||||||
Reference in New Issue
Block a user