Skip to content

Commit

Permalink
thread: safely return NULL from thread_create() if threads not initia…
Browse files Browse the repository at this point in the history
…lized
  • Loading branch information
Akaricchi committed May 13, 2024
1 parent 83dfe8d commit dfa615b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dfa615b

Please sign in to comment.