From 7ebbe4a5ce431a2bf03066ec85513c693836550b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 23 Jan 2023 15:43:35 +0100 Subject: [PATCH] sleep: do not abort if we try to query capacity of missing battery Fixes #25584. From the issue: Assertion 'capacity >= 0' failed at src/shared/sleep-config.c:58, function PTR_TO_CAPACITY(). Aborting. (gdb) bt The problem is that PTR_TO_CAPACITY(hashmap_get(last_capacity, battery_name)) will abort if it's called with a name not present in the hashmap. We want to skip the device silently in this case instead. --- src/shared/sleep-config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 9c5602d617d..84082214ae1 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -495,7 +495,7 @@ int get_total_suspend_interval(Hashmap *last_capacity, usec_t *ret) { continue; } - battery_last_capacity = PTR_TO_CAPACITY(hashmap_get(last_capacity, battery_name)); + battery_last_capacity = get_capacity_by_name(last_capacity, battery_name); if (battery_last_capacity <= 0) continue; -- 2.47.3