summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-11-29 14:03:48 +0100
committerBenBE <BenBE@geshi.org>2020-12-03 13:25:17 +0100
commitd1db9da936630848ebe164e4bdf52155d65b15f8 (patch)
tree38ff6259f2fa91e0c37a67356710b6b06def858f
parent3695cbd5d8dda27f99383437035450814463b633 (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.c5
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) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy