From 915af9546d42f0de6f2bcda552a6fedb0fc645d4 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 22 Feb 2026 22:48:17 +0800 Subject: [PATCH] Keyboard (Linux): supports more keyboard events --- src/detection/keyboard/keyboard_linux.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/detection/keyboard/keyboard_linux.c b/src/detection/keyboard/keyboard_linux.c index 8d1c9ed20..9492710b5 100644 --- a/src/detection/keyboard/keyboard_linux.c +++ b/src/detection/keyboard/keyboard_linux.c @@ -19,9 +19,9 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) if (!ffStrEndsWith(entry->d_name, "-event-kbd")) continue; - char buffer[32]; // `../eventX` + char buffer[32]; // `../eventXX` ssize_t len = readlinkat(dirfd(dirp), entry->d_name, buffer, ARRAY_SIZE(buffer) - 1); - if (len != strlen("../eventX") || !ffStrStartsWith(buffer, "../event")) continue; + if (len <= (ssize_t) strlen("../event") || !ffStrStartsWith(buffer, "../event")) continue; buffer[len] = 0; const char* eventid = buffer + strlen("../event"); @@ -30,8 +30,8 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) uint32_t index = (uint32_t) strtoul(eventid, &pend, 10); if (pend == eventid) continue; - // Ignore duplicate entries - if (flags & (1UL << index)) + // Ignore duplicate entries (flags supports up to 64 event indices) + if (index >= 64 || (flags & (1UL << index))) continue; flags |= (1UL << index); @@ -41,7 +41,7 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) if (ffAppendFileBuffer(path.chars, &name)) { ffStrbufTrimRightSpace(&name); - ffStrbufSubstrBefore(&path, path.length - 4); + ffStrbufSubstrBefore(&path, path.length - (uint32_t) strlen("name")); FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(devices); ffStrbufInitMove(&device->name, &name);