From 4eee9c29436ce29b013d2d80d2762b359e683802 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Fri, 30 Nov 2018 23:41:41 -0500 Subject: [PATCH 5/7] Fix null pointer dereference with no battery present. --- panel-plugin/battery.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/panel-plugin/battery.c b/panel-plugin/battery.c index aa63df6..8502407 100644 --- a/panel-plugin/battery.c +++ b/panel-plugin/battery.c @@ -194,9 +194,8 @@ detect_battery_info(t_battmon *battmon) static gboolean update_apm_status(t_battmon *battmon) { - int charge=0, rate; - - int lcapacity, ccapacity; + int present=0, charge=0, rate=0; + int lcapacity=0, ccapacity=0; gboolean fan=FALSE; const char *temp; static int old_state = -1, new_state = BM_MISSING; @@ -270,10 +269,10 @@ update_apm_status(t_battmon *battmon) if(battmon->method == BM_USE_ACPI) { int i; acline = read_acad_state(); - lcapacity = rate = ccapacity = 0; for (i=0;ilast_full_capacity; ccapacity += acpistate->rcapacity; rate += acpistate->prate; @@ -340,7 +339,7 @@ update_apm_status(t_battmon *battmon) } if(battmon->options.display_icon){ - if((battmon->method == BM_USE_ACPI && acpiinfo->present == 0) || (battmon->method == BM_USE_APM && charge == 0)) { + if((battmon->method == BM_USE_ACPI && present == 0) || (battmon->method == BM_USE_APM && charge == 0)) { /* battery missing */ icon_name = g_strdup("xfce4-battery-missing"); new_state = BM_MISSING; @@ -402,7 +401,7 @@ update_apm_status(t_battmon *battmon) if(acline) { char *t; - if((battmon->method == BM_USE_ACPI && acpiinfo->present == 0) || (battmon->method == BM_USE_APM && charge == 0)) { + if((battmon->method == BM_USE_ACPI && present == 0) || (battmon->method == BM_USE_APM && charge == 0)) { t=_("(No battery, AC on-line)"); } else { t=(charge<99.9)?_("(Charging from AC)"):_("(AC on-line)"); -- 2.19.1