From bb1e4a493f6961144ec62ff4f6533936bed38444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Thu, 31 Aug 2023 16:35:32 +0200 Subject: [PATCH] evdev: Log bug when releasing key with count 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit libinput keeps an internal key count. It is increased by 1 when the key is pressed and decreased by one when the key is released. The count should never be negative, however a user found an issue while running Sway and hit an assert. Replace the assert with a log to avoid the crash. Fix https://gitlab.freedesktop.org/libinput/libinput/-/issues/928 Signed-off-by: José Expósito --- src/evdev.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index 73b394b0..cb49edad 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -135,8 +135,14 @@ evdev_update_key_down_count(struct evdev_device *device, if (pressed) { key_count = ++device->key_count[code]; } else { - assert(device->key_count[code] > 0); - key_count = --device->key_count[code]; + if (device->key_count[code] > 0) { + key_count = --device->key_count[code]; + } else { + evdev_log_bug_libinput(device, + "releasing key %s with count %d\n", + libevdev_event_code_get_name(EV_KEY, code), + device->key_count[code]); + } } if (key_count > 32) {