hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Tue Mar 11 10:00:57 PDT 2008


 hald/util_pm.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

New commits:
commit 88fd8cd367e39ad916bd59f4fcc8735c87426cef
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Tue Mar 11 18:00:13 2008 +0100

    fixed possible segfault from fd.o bug #14947
    
    Fixed possible segfault from fd.o bug #14947 for the case that
    the remaining time is over 60 hours and the chargeRate was never
    before 0 or the rate was never guessed which means saved_battery_info
    wasn't initialised.

diff --git a/hald/util_pm.c b/hald/util_pm.c
index 72fa9f5..e630461 100644
--- a/hald/util_pm.c
+++ b/hald/util_pm.c
@@ -143,10 +143,8 @@ util_compute_time_remaining (const char *id,
 				chargeRate = battery_info->last_chargeRate;
 			} else {
 				chargeRate = ((chargeLevel - battery_info->last_level) * 60 * 60) / (cur_time - battery_info->last_time);
-				/*
-				 * During discharging chargeRate would be negative, which would
-				 * mess up the the calculation below, so we make sure it's always
-				 * positive.
+				/* During discharging chargeRate would be negative, which would mess 
+				 * up the the calculation below, so we make sure it's always positive.
 				 */ 
 				chargeRate = (chargeRate > 0) ? chargeRate : -chargeRate;
 	
@@ -192,6 +190,10 @@ util_compute_time_remaining (const char *id,
 	else if (remaining_time > 60*60*60) {
 		batteryInfo *battery_info;
 
+		/* to be sure saved_battery_info is initialised */
+		if (!saved_battery_info) 
+			saved_battery_info = g_hash_table_new(g_str_hash, g_str_equal);
+
 		if (!(battery_info = g_hash_table_lookup(saved_battery_info, id))) {
 			battery_info = g_new0(batteryInfo, 1);
 			g_hash_table_insert(saved_battery_info, (char*) id, battery_info);


More information about the hal-commit mailing list