From 5fe5027630621f5877c97e8ed63b75e21a1fdd1d Mon Sep 17 00:00:00 2001 From: Luke Yelavich Date: Fri, 21 Sep 2018 08:44:30 +1000 Subject: [PATCH] libobs: Truncate thread names on Linux The pthread_setname_np manpage states: The thread name is a meaningful C language string, whose length is restricted to 16 characters, including the terminating null byte ('\0'). --- libobs/util/threading-posix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libobs/util/threading-posix.c b/libobs/util/threading-posix.c index 435ff1b7b..d02e3d308 100644 --- a/libobs/util/threading-posix.c +++ b/libobs/util/threading-posix.c @@ -253,6 +253,12 @@ void os_set_thread_name(const char *name) #elif defined(__FreeBSD__) pthread_set_name_np(pthread_self(), name); #elif defined(__GLIBC__) && !defined(__MINGW32__) - pthread_setname_np(pthread_self(), name); + if (strlen(name) <= 15) { + pthread_setname_np(pthread_self(), name); + } else { + char *thread_name = bstrdup_n(name, 15); + pthread_setname_np(pthread_self(), thread_name); + bfree(thread_name); + } #endif }