aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bat_tray.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/bat_tray.c b/bat_tray.c
index f9bb1bf..c6e9f45 100644
--- a/bat_tray.c
+++ b/bat_tray.c
@@ -138,11 +138,18 @@ static void update_tooltip_cache()
static gboolean update()
{
char icon_file[1024];
- unsigned int rounded = 0;
+ int rounded = 0;
/* Round percentage to 0, 20, 40, 60, 80 or 100 */
rounded = 20 * (int)((get_bat_percent() + 10) / 20);
+ /* cap rounded value to safe bounds */
+ if (rounded < 0)
+ rounded = 0;
+
+ if (rounded > 100)
+ rounded = 100;
+
switch (get_battery_state())
{
case STATE_DISCHARGING: