Fixed bug #5283 - limit thread name to 16 characters when using pthread_setname_np()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c
index 41184de..fb68b24 100644
--- a/src/thread/pthread/SDL_systhread.c
+++ b/src/thread/pthread/SDL_systhread.c
@@ -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
@@ -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
}