Package: yacpi
Version: 2.0.1-1
Severity: normal
Tags: patch


If there is no battery info, yacpi crashes right after startup with NULL
pointer reference. See the attached patch


-- System Information:
Debian Release: 3.1
Architecture: i386 (i686)
Kernel: Linux 2.6.17.11
Locale: LANG=hu_HU, LC_CTYPE=hu_HU (charmap=ISO-8859-2)

Versions of packages yacpi depends on:
ii libc6 2.3.5-6 GNU C Library: Shared libraries an ii libncurses5 5.4-4 Shared libraries for terminal hand

-- no debconf information
--- yacpi-1.2.1/yacpi.c.orig    2005-03-30 21:35:39.000000000 +0200
+++ yacpi-1.2.1/yacpi.c 2006-08-30 08:03:29.000000000 +0200
@@ -227,7 +227,7 @@
     if (COLS <= 87) {
         for (i = 0; i < globals->battery_count; i++) {
             binfo = &batteries[i];
-            if (binfo->present) {
+            if (binfo && binfo->present) {
                 mvprintw (line, 0, "Battery %s on %2d%%", binfo->name,
                           binfo->percentage);
                 line = line + 2;
@@ -247,14 +247,16 @@
             attroff(COLOR_PAIR(3));
         }
         line=line+2;
-        if (binfo->charge_state == CHARGE)
-            mvprintw (line, 0, "Battery Status: charging   ");
-        else if (binfo->charge_state == DISCHARGE)
-            mvprintw (line, 0, "Battery Status: discharging");
-        else if (binfo->charge_state == CHARGED)
-            mvprintw (line, 0, "Battery Status: charged    ");
-        else if (binfo->charge_state == NOINFO)
-            mvprintw (line, 0, "Battery Status: not supported");
+               if (binfo) {
+            if (binfo->charge_state == CHARGE)
+                mvprintw (line, 0, "Battery Status: charging   ");
+            else if (binfo->charge_state == DISCHARGE)
+                mvprintw (line, 0, "Battery Status: discharging");
+            else if (binfo->charge_state == CHARGED)
+                mvprintw (line, 0, "Battery Status: charged    ");
+            else if (binfo->charge_state == NOINFO)
+                mvprintw (line, 0, "Battery Status: not supported");
+               }
         line = line + 2;
         if (globals->rtime >= 0 && ap->power != AC) {
             mvprintw (line, 0, "Remaining time: %02d:%02d h        ",
@@ -262,7 +264,7 @@
             line = line + 2;
         }
 
-        if (ap->power == AC && binfo->charge_time >= 0) {
+        if (ap->power == AC && binfo && binfo->charge_time >= 0) {
             mvprintw (line, 0, "Remaining charge time: %02d:%02d h",
                       binfo->charge_time / 60, binfo->charge_time % 60);
             line = line + 2;
@@ -280,7 +282,7 @@
     else {
         for (i = 0; i < globals->battery_count; i++) {
             binfo = &batteries[i];
-            if (binfo->present) {
+            if (binfo && binfo->present) {
                 mvprintw (line, 0, "%s Capacity [", binfo->name);
                 color_change (binfo->percentage, 0);
                 for (i = 0; i <= (binfo->percentage / 2); i++)
@@ -306,14 +308,16 @@
             attroff(COLOR_PAIR(3));
         }
         line = line + 2;
-        if (binfo->charge_state == CHARGE)
-            mvprintw (line, 0, "Battery Status: charging   ");
-        else if (binfo->charge_state == DISCHARGE)
-            mvprintw (line, 0, "Battery Status: discharging");
-        else if (binfo->charge_state == CHARGED)
-            mvprintw (line, 0, "Battery Status: charged    ");
-        else if (binfo->charge_state == NOINFO)
-            mvprintw (line, 0, "Battery Status: not supported");
+               if (binfo) {
+            if (binfo->charge_state == CHARGE)
+                mvprintw (line, 0, "Battery Status: charging   ");
+            else if (binfo->charge_state == DISCHARGE)
+                mvprintw (line, 0, "Battery Status: discharging");
+            else if (binfo->charge_state == CHARGED)
+                mvprintw (line, 0, "Battery Status: charged    ");
+            else if (binfo->charge_state == NOINFO)
+                mvprintw (line, 0, "Battery Status: not supported");
+           }
 
         line = line + 2;
         if (globals->rtime >= 0 && ap->power != AC) {
@@ -321,7 +325,7 @@
                       globals->rtime / 60, globals->rtime % 60);
             line = line + 2;
         }
-        if (ap->power == AC && binfo->charge_time >= 0) {
+        if (ap->power == AC && binfo && binfo->charge_time >= 0) {
             mvprintw (line, 0, "Remaining charge time: %02d:%02d h",
                       binfo->charge_time / 60, binfo->charge_time % 60);
             line = line + 2;

Reply via email to