diff --git a/src/coreclr/src/pal/src/thread/thread.cpp b/src/coreclr/src/pal/src/thread/thread.cpp index 1473601c51252..159ef03cf0b60 100644 --- a/src/coreclr/src/pal/src/thread/thread.cpp +++ b/src/coreclr/src/pal/src/thread/thread.cpp @@ -1666,7 +1666,10 @@ CorUnix::InternalSetThreadDescription( // Null terminate early. // pthread_setname_np only accepts up to 16 chars. - nameBuf[15] = '\0'; + if (nameSize > 15) + { + nameBuf[15] = '\0'; + } error = pthread_setname_np(pTargetThread->GetPThreadSelf(), nameBuf);