sdl12-compat: PollEvent, WaitEvent, PeepEvents can all take a NULL event pointer.

From ba45fa3ae5cc776664d001b3b04971237729a2db Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 28 May 2021 19:31:32 -0400
Subject: [PATCH] PollEvent, WaitEvent, PeepEvents can all take a NULL event
 pointer.

Fixes crash in icebreaker when using the menu.

Reference Bug #68.
---
 src/SDL12_compat.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index eb1947c..9124bbe 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -1736,13 +1736,15 @@ SDL_PollEvent(SDL12_Event *event12)
         return 0;  /* no events at the moment. */
     }
 
-    SDL20_memcpy(event12, &EventQueueHead->event12, sizeof (SDL12_Event));
-    next = EventQueueHead->next;
-    EventQueueHead->next = EventQueueAvailable;
-    EventQueueAvailable = EventQueueHead;
-    EventQueueHead = next;
-    if (!next) {
-        EventQueueTail = NULL;
+    if (event12 != NULL) {
+        SDL20_memcpy(event12, &EventQueueHead->event12, sizeof (SDL12_Event));
+        next = EventQueueHead->next;
+        EventQueueHead->next = EventQueueAvailable;
+        EventQueueAvailable = EventQueueHead;
+        EventQueueHead = next;
+        if (!next) {
+            EventQueueTail = NULL;
+        }
     }
 
     return 1;
@@ -1773,6 +1775,8 @@ SDL_PushEvent(SDL12_Event *event12)
 DECLSPEC int SDLCALL
 SDL_PeepEvents(SDL12_Event *events12, int numevents, SDL_eventaction action, Uint32 mask)
 {
+    SDL12_Event dummy_event;
+
     if (action == SDL_ADDEVENT) {
         int i;
         for (i = 0; i < numevents; i++) {
@@ -1782,6 +1786,12 @@ SDL_PeepEvents(SDL12_Event *events12, int numevents, SDL_eventaction action, Uin
         return i;
     }
 
+    if (!events12) {
+        action = SDL_PEEKEVENT;
+        numevents = 1;
+        events12 = &dummy_event;
+    }
+
     if ((action == SDL_PEEKEVENT) || (action == SDL_GETEVENT)) {
         const SDL_bool isGet = (action == SDL_GETEVENT)? SDL_TRUE : SDL_FALSE;
         EventQueueType *prev = NULL;
@@ -1828,8 +1838,9 @@ DECLSPEC int SDLCALL
 SDL_WaitEvent(SDL12_Event *event12)
 {
     FIXME("In 1.2, this only fails (-1) if you haven't SDL_Init()'d.");
-    while (!SDL_PollEvent(event12))
+    while (!SDL_PollEvent(event12)) {
         SDL20_Delay(10);
+    }
     return 1;
 }