bbidulock / icewm

A window manager designed for speed, usability, and consistency
Other
585 stars 98 forks source link

Fix overflows in battery calculations #607

Closed jiribohac closed 3 years ago

jiribohac commented 3 years ago

commit 52113d9fbf936b6242afbe7897a8918a747810b2 (fix battery divisions) actually broke the battery divisions by using int divisions, causing the following calculations to overflow: (100 * BATcapacity_remain) / BATcapacity_full

My battery status showed "-19%". Values read from sysfs: BATcapacity_remain = 35140000 BATcapacity_full = 39240000

100 * 35140000 overflows the 31 bits of a signed int so the calculation results in -780967296 / 39240000 = -19.

Force these calculatoins to be long long to avoid the overflow. The BATtime_remain calculation just barely does not overflow for me but fix this as well.

gijsbers commented 3 years ago

Thanks a lot for reporting this! I made some more changes to the APM module.