From dfa615bb7795439df795136119c5b4dc43490bc4 Mon Sep 17 00:00:00 2001 From: Andrei Alexeyev Date: Mon, 13 May 2024 03:30:19 +0200 Subject: [PATCH] thread: safely return NULL from thread_create() if threads not initialized --- src/thread.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/thread.c b/src/thread.c index f8c1e050c9..d3c0544374 100644 --- a/src/thread.c +++ b/src/thread.c @@ -134,6 +134,11 @@ static int SDLCALL sdlthread_entry(void *data) { } Thread *thread_create(const char *name, ThreadProc proc, void *userdata, ThreadPriority prio) { + if(UNLIKELY(!threads.main_id)) { + log_error("Thread subsystem is not initialized"); + return NULL; + } + size_t nsize = strlen(name) + 1; auto thrd = ALLOC_FLEX(Thread, nsize); memcpy(thrd->name, name, nsize);