Skip to content

Commit

Permalink
Fixed bug #5283 - limit thread name to 16 characters when using pthre…
Browse files Browse the repository at this point in the history
…ad_setname_np()
  • Loading branch information
1bsyl committed Feb 2, 2022
1 parent b11dfd7 commit 9e46a51
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/thread/pthread/SDL_systhread.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "../../core/linux/SDL_dbus.h"
#endif /* __LINUX__ */

#undef HAVE_DLOPEN

#if (defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__)) && defined(HAVE_DLOPEN)
#include <dlfcn.h>
#ifndef RTLD_DEFAULT
Expand Down Expand Up @@ -137,22 +139,25 @@ SDL_SYS_SetupThread(const char *name)
#if defined(__MACOSX__) || defined(__IPHONEOS__)
ppthread_setname_np(name);
#elif defined(__LINUX__)
ppthread_setname_np(pthread_self(), name);
char namebuf[16]; /* Limited to 16 char */
SDL_strlcpy(namebuf, name, sizeof (namebuf));
ppthread_setname_np(pthread_self(), namebuf);
#endif
}
#elif HAVE_PTHREAD_SETNAME_NP
#if defined(__NETBSD__)
pthread_setname_np(pthread_self(), "%s", name);
#else
pthread_setname_np(pthread_self(), name);
char namebuf[16]; /* Limited to 16 char */
SDL_strlcpy(namebuf, name, sizeof (namebuf));
pthread_setname_np(pthread_self(), namebuf);
#endif
#elif HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name);
#elif defined(__HAIKU__)
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
char namebuf[B_OS_NAME_LENGTH];
SDL_snprintf(namebuf, sizeof (namebuf), "%s", name);
namebuf[sizeof (namebuf) - 1] = '\0';
SDL_strlcpy(namebuf, name, sizeof (namebuf));
rename_thread(find_thread(NULL), namebuf);
#endif
}
Expand Down

0 comments on commit 9e46a51

Please sign in to comment.