From 6c8d35abf057fd3f1a618e078cb3ef2d0e81a4bb Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Tue, 4 Mar 2008 03:35:03 +0000 Subject: [PATCH] let's just put all things that multiply that could possibly be big numbers be long long to avoid overflows. :) SVN revision: 33911 --- src/modules/battery/batget.c | 16 ++++++++-------- src/modules/battery/e_mod_main.c | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/modules/battery/batget.c b/src/modules/battery/batget.c index 9589f17f5..1ea030ad3 100644 --- a/src/modules/battery/batget.c +++ b/src/modules/battery/batget.c @@ -725,7 +725,7 @@ linux_sys_class_power_supply_check(void) else { if (pwr_now < 0) - pwr_now = ((capacity * (pwr_full - pwr_empty)) / 100) + pwr_empty; + pwr_now = (((long long)capacity * ((long long)pwr_full - (long long)pwr_empty)) / 100) + pwr_empty; } if (sysev->present) have_battery = 1; @@ -744,7 +744,7 @@ linux_sys_class_power_supply_check(void) else if (current < 0) time_left = -1; else { - pwr = ((pwr_full - pwr_now) * 3600) / -current; + pwr = (((long long)pwr_full - (long long)pwr_now) * 3600) / -current; if (pwr > time_left) time_left = pwr; } } @@ -759,7 +759,7 @@ linux_sys_class_power_supply_check(void) { if (current > 0) { - pwr = ((pwr_now - pwr_empty) * 3600) / current; + pwr = (((long long)pwr_now - (long long)pwr_empty) * 3600) / current; time_left += pwr; } } @@ -1063,18 +1063,18 @@ linux_acpi_check(void) } ecore_list_destroy(bats); if (acpi_max_full > 0) - battery_full = 100 * capacity / acpi_max_full; + battery_full = 100 * (long long)capacity / acpi_max_full; else if (acpi_max_design > 0) - battery_full = 100 * capacity / acpi_max_design; + battery_full = 100 * (long long)capacity / acpi_max_design; else battery_full = -1; if (rate <= 0) time_left = -1; else { if (have_power) - time_left = (3600 * (acpi_max_full - capacity)) / rate; + time_left = (3600 * ((long long)acpi_max_full - (long long)capacity)) / rate; else - time_left = (3600 * capacity) / rate; + time_left = (3600 * (long long)capacity) / rate; } } } @@ -1290,7 +1290,7 @@ linux_pmu_check(void) } } ecore_list_destroy(bats); - if (max_charge > 0) battery_full = (charge * 100) / max_charge; + if (max_charge > 0) battery_full = ((long long)charge * 100) / max_charge; else battery_full = 0; time_left = seconds; } diff --git a/src/modules/battery/e_mod_main.c b/src/modules/battery/e_mod_main.c index bd949a785..549c1d10e 100644 --- a/src/modules/battery/e_mod_main.c +++ b/src/modules/battery/e_mod_main.c @@ -240,7 +240,7 @@ e_modapi_init(E_Module *m) E_CONFIG_LIMIT(battery_config->poll_interval, 4, 4096); E_CONFIG_LIMIT(battery_config->alarm, 0, 60); E_CONFIG_LIMIT(battery_config->alarm_p, 0, 100); - + battery_config->module = m; battery_config->full = -2;