From 4a9f5500691a2a90ced56598bc8185d05fe416a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 10 Nov 2020 22:26:49 +0100 Subject: [PATCH] =?UTF-8?q?module/battery:=20don=E2=80=99t=20crash=20if=20?= =?UTF-8?q?we=20fail=20to=20read=20from=20=E2=80=98status=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/battery.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/battery.c b/modules/battery.c index 4759a99..99bad3c 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -291,7 +291,10 @@ update_status(struct module *mod, int capacity_fd, int energy_fd, int power_fd, const char *status = readline_from_fd(status_fd); enum state state; - if (strcmp(status, "Full") == 0) + if (status == NULL) { + LOG_WARN("failed to read battery state"); + state = STATE_DISCHARGING; + } else if (strcmp(status, "Full") == 0) state = STATE_FULL; else if (strcmp(status, "Charging") == 0) state = STATE_CHARGING;