Commit a5fd94a4 authored by Anton Likhtarov's avatar Anton Likhtarov Committed by Facebook Github Bot

getThreadName(): handle bad std::thread::id gracefully

Summary: pthread_getname_np() tries to dereference 0 when called with it, let's turn it into an error instead

Reviewed By: yfeldblum

Differential Revision: D15708351

fbshipit-source-id: aa2dd92e12e33174c8998daed056de50d4111774
parent d1c34f8e
...@@ -91,7 +91,8 @@ Optional<std::string> getThreadName(std::thread::id id) { ...@@ -91,7 +91,8 @@ Optional<std::string> getThreadName(std::thread::id id) {
#if FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME || \ #if FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME || \
FOLLY_HAS_PTHREAD_SETNAME_NP_NAME FOLLY_HAS_PTHREAD_SETNAME_NP_NAME
std::array<char, kMaxThreadNameLength> buf; std::array<char, kMaxThreadNameLength> buf;
if (pthread_getname_np(stdTidToPthreadId(id), buf.data(), buf.size()) != 0) { if (id == std::thread::id() ||
pthread_getname_np(stdTidToPthreadId(id), buf.data(), buf.size()) != 0) {
return Optional<std::string>(); return Optional<std::string>();
} }
return folly::make_optional(std::string(buf.data())); return folly::make_optional(std::string(buf.data()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment