From 2e9f7077c90155022a315cdd9b270b059e380771 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 7 Jul 2026 17:50:00 +0300 Subject: [PATCH] TaskBar: Fix division by zero error If a CPU does not have updated stats to show, just display ??.??% --- userspace/programs/TaskBar/main.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/userspace/programs/TaskBar/main.cpp b/userspace/programs/TaskBar/main.cpp index d09a4f6d..52fafa78 100644 --- a/userspace/programs/TaskBar/main.cpp +++ b/userspace/programs/TaskBar/main.cpp @@ -116,11 +116,17 @@ static BAN::String get_cpu_load(bool show_long) } BAN::String result; - (void)result.append("CPU"); + (void)result.append("CPU"_sv); - for (size_t i = 0; i < delta_stats.size(); i++) + for (const auto stats : delta_stats) { - const uint64_t idle_10000 = 10'000 * delta_stats[i].idle_ns / delta_stats[i].total_ns; + if (stats.total_ns == 0) + { + (void)result.append(" ??.??%"_sv); + continue; + } + + const uint64_t idle_10000 = 10'000 * stats.idle_ns / stats.total_ns; const uint64_t load_10000 = 10'000 - idle_10000; auto string = BAN::String::formatted(" {}.{2}%", load_10000 / 100, load_10000 % 100);