From 87b02d3795cef947360bd24519bb0d0fa777243f Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 2 Feb 2022 15:09:29 +0100 Subject: [PATCH] Linux thread name limitation: test for ERANGE (see bug #5283) --- src/thread/pthread/SDL_systhread.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c index b89256544..473c710a8 100644 --- a/src/thread/pthread/SDL_systhread.c +++ b/src/thread/pthread/SDL_systhread.c @@ -137,18 +137,22 @@ SDL_SYS_SetupThread(const char *name) #if defined(__MACOSX__) || defined(__IPHONEOS__) ppthread_setname_np(name); #elif defined(__LINUX__) - char namebuf[16]; /* Limited to 16 char */ - SDL_strlcpy(namebuf, name, sizeof (namebuf)); - ppthread_setname_np(pthread_self(), namebuf); + if (ppthread_setname_np(pthread_self(), name) == ERANGE) { + 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 - char namebuf[16]; /* Limited to 16 char */ - SDL_strlcpy(namebuf, name, sizeof (namebuf)); - pthread_setname_np(pthread_self(), namebuf); + if (pthread_setname_np(pthread_self(), name) == ERANGE) { + 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);