From a7f3351c0efcd04dcbe11753935a7cb9f21e0e94 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 18 Dec 2024 18:36:26 +0200 Subject: [PATCH] TaskBar: Prevent possible division by zero If battery reports its full capacity as zero, battery percentage calculation did a division by zero crashing the TaskBar :) --- userspace/programs/TaskBar/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/userspace/programs/TaskBar/main.cpp b/userspace/programs/TaskBar/main.cpp index 0acf23eb..e76ae768 100644 --- a/userspace/programs/TaskBar/main.cpp +++ b/userspace/programs/TaskBar/main.cpp @@ -38,7 +38,7 @@ static BAN::String get_battery_percentage() sprintf(buffer, "/dev/batteries/%s/capacity_full", dirent->d_name); auto cap_full = read_integer_from_file(buffer); - if (cap_full.is_error()) + if (cap_full.is_error() || cap_full.value() == 0) continue; sprintf(buffer, "/dev/batteries/%s/capacity_now", dirent->d_name);