From bd622c304ac9080999c4afb852f5e1f67d7115a5 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 22 Sep 2017 21:45:35 +0200 Subject: [PATCH] Limit pthread thread name to 16 bytes. This is a documented pthread restriction. Passing longer strings has no effect (i.e. thread name is not set). --- common/TracySystem.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index 97ff47be..edf496d9 100755 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -48,7 +48,18 @@ void SetThreadName( std::thread& thread, const char* name ) } # endif #else - pthread_setname_np( thread.native_handle(), name ); + const auto sz = strlen( name ); + if( sz <= 15 ) + { + pthread_setname_np( thread.native_handle(), name ); + } + else + { + char buf[16]; + memcpy( buf, name, 15 ); + buf[15] = '\0'; + pthread_setname_np( thread.native_handle(), sz ); + } #endif }