Commit 73680ab3740392904a72309ccf3d7a6757a049cb

Ryan C. Gordon 2016-01-07T16:01:24

Fixed NULL dereference on drop events with no window associated. (such as when dropping a file onto an app's icon to launch.) This bug caught by Clang's static analyzer.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/events/SDL_dropevents.c b/src/events/SDL_dropevents.c
index ba4dcd6..49b07d9 100644
--- a/src/events/SDL_dropevents.c
+++ b/src/events/SDL_dropevents.c
@@ -43,7 +43,11 @@ SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *data)
         if (need_begin) {
             SDL_zero(event);
             event.type = SDL_DROPBEGIN;
-            event.drop.windowID = window->id;
+
+            if (window) {
+                event.drop.windowID = window->id;
+            }
+
             posted = (SDL_PushEvent(&event) > 0);
             if (!posted) {
                 return 0;