From 41532e84cbb3459cd73bb072589180cdef9aad22 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Fri, 14 Jun 2024 12:25:13 -0400 Subject: [PATCH] wayland: Prevent a possible crash when determining the display for a minimized window A minimized window may not be associated with any displays, so check that the output array is valid and that there is at least one associated display before dereferencing. Fixes a crash when attempting to unset fullscreen on a minimized window. --- src/video/wayland/SDL_waylandwindow.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index 54aff97311..756308f98d 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -494,9 +494,16 @@ static void FlushFullscreenEvents(SDL_Window *window) static void Wayland_move_window(SDL_Window *window) { SDL_WindowData *wind = window->driverdata; - SDL_DisplayData *display = wind->outputs[wind->num_outputs - 1]; + SDL_DisplayData *display; SDL_DisplayID *displays; + if (wind->outputs && wind->num_outputs) { + display = wind->outputs[wind->num_outputs - 1]; + } else { + /* A window may not be on any displays if minimized. */ + return; + } + displays = SDL_GetDisplays(NULL); if (displays) { for (int i = 0; displays[i]; ++i) {