netstar pushed a commit to branch master. http://git.enlightenment.org/apps/evisum.git/commit/?id=d5c10b939d1f6cd1f19967d0e0a935e8bceef6a5
commit d5c10b939d1f6cd1f19967d0e0a935e8bceef6a5 Author: Alastair Poole <[email protected]> Date: Thu Jun 18 12:45:06 2020 +0100 machine: fix index --- src/bin/system/machine.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/bin/system/machine.c b/src/bin/system/machine.c index fd734ff..915af88 100644 --- a/src/bin/system/machine.c +++ b/src/bin/system/machine.c @@ -797,7 +797,7 @@ _power_battery_count_get(power_t *power) char *type; char path[PATH_MAX]; struct dirent **names; - int i, n; + int i, n, id; n = scandir("/sys/class/power_supply", &names, 0, alphasort); if (n < 0) return power->battery_count; @@ -812,11 +812,12 @@ _power_battery_count_get(power_t *power) { if (!strncmp(type, "Battery", 7)) { - power->batteries = realloc(power->batteries, 1 + - power->battery_count * sizeof(bat_t **)); - power->batteries[i] = calloc(1, sizeof(bat_t)); - power->batteries[i]->name = strdup(names[i]->d_name); - power->batteries[i]->present = true; + id = power->battery_count; + power->batteries = realloc(power->batteries, (1 + + power->battery_count) * sizeof(bat_t **)); + power->batteries[id] = calloc(1, sizeof(bat_t)); + power->batteries[id]->name = strdup(names[i]->d_name); + power->batteries[id]->present = true; power->battery_count++; } free(type); --
