evdev: Log bug when releasing key with count 0

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 <jose.exposito89@gmail.com>
This commit is contained in:
José Expósito 2023-08-31 16:35:32 +02:00
parent 17e556503d
commit bb1e4a493f

View file

@ -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) {