瀏覽代碼

wayland: Never commit with an undefined window title

If libdecor performs a commit with the frame title being undefined, a crash can occur within the library or its plugins. Always ensure that the title is set to a valid string to avoid this.
Frank Praznik 3 年之前
父節點
當前提交
7da74eb5be
共有 1 個文件被更改,包括 10 次插入11 次删除
  1. 10 11
      src/video/wayland/SDL_waylandwindow.c

+ 10 - 11
src/video/wayland/SDL_waylandwindow.c

@@ -2069,26 +2069,25 @@ void Wayland_SetWindowTitle(_THIS, SDL_Window * window)
 {
 {
     SDL_WindowData *wind = window->driverdata;
     SDL_WindowData *wind = window->driverdata;
     SDL_VideoData *viddata = _this->driverdata;
     SDL_VideoData *viddata = _this->driverdata;
+    const char *title = window->title ? window->title : "";
 
 
     if (WINDOW_IS_XDG_POPUP(window)) {
     if (WINDOW_IS_XDG_POPUP(window)) {
         return;
         return;
     }
     }
 
 
-    if (window->title != NULL) {
 #ifdef HAVE_LIBDECOR_H
 #ifdef HAVE_LIBDECOR_H
-        if (WINDOW_IS_LIBDECOR(viddata, window)) {
-            if (wind->shell_surface.libdecor.frame == NULL) {
-                return; /* Can't do anything yet, wait for ShowWindow */
-            }
-            libdecor_frame_set_title(wind->shell_surface.libdecor.frame, window->title);
-        } else
+    if (WINDOW_IS_LIBDECOR(viddata, window)) {
+        if (wind->shell_surface.libdecor.frame == NULL) {
+            return; /* Can't do anything yet, wait for ShowWindow */
+        }
+        libdecor_frame_set_title(wind->shell_surface.libdecor.frame, title);
+    } else
 #endif
 #endif
         if (viddata->shell.xdg) {
         if (viddata->shell.xdg) {
-            if (wind->shell_surface.xdg.roleobj.toplevel == NULL) {
-                return; /* Can't do anything yet, wait for ShowWindow */
-            }
-            xdg_toplevel_set_title(wind->shell_surface.xdg.roleobj.toplevel, window->title);
+        if (wind->shell_surface.xdg.roleobj.toplevel == NULL) {
+            return; /* Can't do anything yet, wait for ShowWindow */
         }
         }
+        xdg_toplevel_set_title(wind->shell_surface.xdg.roleobj.toplevel, title);
     }
     }
 
 
     WAYLAND_wl_display_flush(viddata->display);
     WAYLAND_wl_display_flush(viddata->display);