diff options
author | Gunnar Beutner <gunnar@beutner.name> | 2021-04-17 02:14:44 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-04-17 09:25:06 +0200 |
commit | dd0a4b36fb6b9dde180d460a647144cf7b6cb90a (patch) | |
tree | 70a748a3c3a9f2467a749f6b567d1f5dc8a1357e | |
parent | 873da38d0e619ecea1e7956696aac8ac7013540d (diff) | |
download | serenity-dd0a4b36fb6b9dde180d460a647144cf7b6cb90a.zip |
Utilities: Fix division by zero
top crashes when sum_diff is zero.
CrashDaemon(15): --- Backtrace for thread #0 (TID 3052) ---
CrashDaemon(15): 0x96537f56: [/bin/top] main +0x4f6 (top.cpp:204)
CrashDaemon(15): 0x96538138: [/bin/top] _start +0x58 (crt0.cpp:58)
-rw-r--r-- | Userland/Utilities/top.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Utilities/top.cpp b/Userland/Utilities/top.cpp index c53dfb88f0..f42ba9593f 100644 --- a/Userland/Utilities/top.cpp +++ b/Userland/Utilities/top.cpp @@ -201,8 +201,8 @@ int main(int, char**) u32 times_scheduled_before = (*jt).value.times_scheduled; u32 times_scheduled_diff = times_scheduled_now - times_scheduled_before; it.value.times_scheduled_since_prev = times_scheduled_diff; - it.value.cpu_percent = ((times_scheduled_diff * 100) / sum_diff); - it.value.cpu_percent_decimal = (((times_scheduled_diff * 1000) / sum_diff) % 10); + it.value.cpu_percent = sum_diff > 0 ? ((times_scheduled_diff * 100) / sum_diff) : 0; + it.value.cpu_percent_decimal = sum_diff > 0 ? (((times_scheduled_diff * 1000) / sum_diff) % 10) : 0; threads.append(&it.value); } |