[llvm] r325069 - Fix off-by-one in set_thread_name which causes truncation to fail on Linux

Sam McCall via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 15:23:59 PST 2018


Author: sammccall
Date: Tue Feb 13 15:23:59 2018
New Revision: 325069

URL: http://llvm.org/viewvc/llvm-project?rev=325069&view=rev
Log:
Fix off-by-one in set_thread_name which causes truncation to fail on Linux

Modified:
    llvm/trunk/lib/Support/Unix/Threading.inc

Modified: llvm/trunk/lib/Support/Unix/Threading.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Threading.inc?rev=325069&r1=325068&r2=325069&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Threading.inc (original)
+++ llvm/trunk/lib/Support/Unix/Threading.inc Tue Feb 13 15:23:59 2018
@@ -138,8 +138,9 @@ void llvm::set_thread_name(const Twine &
   // terminated, but additionally the end of a long thread name will usually
   // be more unique than the beginning, since a common pattern is for similar
   // threads to share a common prefix.
+  // Note that the name length includes the null terminator.
   if (get_max_thread_name_length() > 0)
-    NameStr = NameStr.take_back(get_max_thread_name_length());
+    NameStr = NameStr.take_back(get_max_thread_name_length() - 1);
   (void)NameStr;
 #if defined(__linux__)
 #if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)




More information about the llvm-commits mailing list