Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflows in battery calculations #607

Closed

Commits on Aug 28, 2021

  1. Fix overflows in battery calculations

    commit 52113d9 (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.
    jiribohac committed Aug 28, 2021
    Configuration menu
    Copy the full SHA
    c1ac19b View commit details
    Browse the repository at this point in the history