Browse Source

WIN_GetDrawableSize: avoid NULL pointer dereference

Fixes https://github.com/libsdl-org/SDL/issues/6356
Ozkan Sezer 2 years ago
parent
commit
4726270ead
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/video/windows/SDL_windowswindow.c

+ 8 - 2
src/video/windows/SDL_windowswindow.c

@@ -1408,10 +1408,16 @@ WIN_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
 void
 WIN_GetDrawableSize(const SDL_Window *window, int *w, int *h)
 {
-    const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata);
-    HWND hwnd = data->hwnd;
+    HWND hwnd;
     RECT rect;
 
+    if (!window || !(window->driverdata)) {
+        *w = 0;
+        *h = 0;
+        return;
+    }
+
+    hwnd = ((SDL_WindowData *)window->driverdata)->hwnd;
     if (GetClientRect(hwnd, &rect)) {
         *w = rect.right;
         *h = rect.bottom;