diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2020-11-29 14:03:48 +0100 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2020-12-03 13:25:17 +0100 |
commit | d1db9da936630848ebe164e4bdf52155d65b15f8 (patch) | |
tree | 38ff6259f2fa91e0c37a67356710b6b06def858f | |
parent | 3695cbd5d8dda27f99383437035450814463b633 (diff) |
Linux: avoid float division by 0 after system sleep
linux/LinuxProcessList.c:1403:63: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/LinuxProcessList.c:1403:63 in
-rw-r--r-- | linux/LinuxProcessList.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 46850e1a..2bad64a5 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1362,8 +1362,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ LinuxProcess_updateIOPriority(lp); } - float percent_cpu = (lp->utime + lp->stime - lasttimes) / period * 100.0; - proc->percent_cpu = isnan(percent_cpu) ? 0.0 : CLAMP(percent_cpu, 0.0, cpus * 100.0); + /* period might be 0 after system sleep */ + float percent_cpu = (period < 1e-6) ? 0.0f : ((lp->utime + lp->stime - lasttimes) / period * 100.0); + proc->percent_cpu = CLAMP(percent_cpu, 0.0f, cpus * 100.0f); proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(pl->totalMem) * 100.0; if (!preExisting) { |