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 :)
This commit is contained in:
Bananymous 2024-12-18 18:36:26 +02:00
parent 3a6cdfff45
commit a7f3351c0e
1 changed files with 1 additions and 1 deletions

View File

@ -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);