SDL: Added more error checking for SDL timer functions

From aaa9bf94223c99dd18afb9516a93f9bd7968e65a Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 27 May 2024 07:31:20 -0700
Subject: [PATCH] Added more error checking for SDL timer functions

---
 src/timer/SDL_timer.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c
index e6e5094982205..ca98271d66de1 100644
--- a/src/timer/SDL_timer.c
+++ b/src/timer/SDL_timer.c
@@ -279,6 +279,11 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
     SDL_Timer *timer;
     SDL_TimerMap *entry;
 
+    if (!callback_ms && !callback_ns) {
+        SDL_InvalidParamError("callback");
+        return 0;
+    }
+
     SDL_LockSpinlock(&data->lock);
     if (!SDL_AtomicGet(&data->active)) {
         if (SDL_InitTimers() < 0) {
@@ -350,6 +355,10 @@ int SDL_RemoveTimer(SDL_TimerID id)
     SDL_TimerMap *prev, *entry;
     SDL_bool canceled = SDL_FALSE;
 
+    if (!id) {
+        return SDL_InvalidParamError("id");
+    }
+
     /* Find the timer */
     SDL_LockMutex(data->timermap_lock);
     prev = NULL;
@@ -439,6 +448,11 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m
     SDL_TimerData *data = &SDL_timer_data;
     SDL_TimerMap *entry;
 
+    if (!callback_ms && !callback_ns) {
+        SDL_InvalidParamError("callback");
+        return 0;
+    }
+
     entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry));
     if (!entry) {
         return 0;
@@ -474,6 +488,10 @@ int SDL_RemoveTimer(SDL_TimerID id)
     SDL_TimerData *data = &SDL_timer_data;
     SDL_TimerMap *prev, *entry;
 
+    if (!id) {
+        return SDL_InvalidParamError("id");
+    }
+
     /* Find the timer */
     prev = NULL;
     for (entry = data->timermap; entry; prev = entry, entry = entry->next) {