浏览代码

wayland: Avoid infinite loop in keyboard_repeat_handle

If `repeat_info->next_repeat_ms` overflows, many key presses will be generated.
In the worst case, `now = 0xFFFFFFFFU` and the loop will never terminate.

Rearrange the comparison in order to gracefully handle the overflow case.

Signed-off-by: Joan Bruguera <[email protected]>
Joan Bruguera 3 年之前
父节点
当前提交
fb0c3040c0
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      src/video/wayland/SDL_waylandevents.c

+ 1 - 1
src/video/wayland/SDL_waylandevents.c

@@ -210,7 +210,7 @@ keyboard_repeat_handle(SDL_WaylandKeyboardRepeat* repeat_info, uint32_t now)
     if (!repeat_info->is_key_down || !repeat_info->is_initialized) {
     if (!repeat_info->is_key_down || !repeat_info->is_initialized) {
         return ret;
         return ret;
     }
     }
-    while (repeat_info->next_repeat_ms <= now) {
+    while ((now - repeat_info->next_repeat_ms) < 0x80000000U) {
         if (repeat_info->scancode != SDL_SCANCODE_UNKNOWN) {
         if (repeat_info->scancode != SDL_SCANCODE_UNKNOWN) {
             SDL_SendKeyboardKey(SDL_PRESSED, repeat_info->scancode);
             SDL_SendKeyboardKey(SDL_PRESSED, repeat_info->scancode);
         }
         }