summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-08-03 00:25:00 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-08-03 00:25:00 +0000
commite4e4f4e88de083bf4c918418658b620961f33847 (patch)
treeaa8565a365f7aec8f72b95bfaaa81329f1db3804
parentabe7b89be678981508f4bce18035054b35f703f7 (diff)
parent517000a4a7bdb63392d2107b3aadd2710619bc17 (diff)
downloadadb-e4e4f4e88de083bf4c918418658b620961f33847.tar.gz
Merge "Fix reference to out of scope local in adb_thread_setname." am: b31ca1a64f am: 15d565bbca
am: b664dd38b9 Change-Id: Id2d91a34d11400cdb4b601da745d64209aeb3e71
-rw-r--r--sysdeps.h18
1 files changed, 6 insertions, 12 deletions
diff --git a/sysdeps.h b/sysdeps.h
index 49c7847..0abb680 100644
--- a/sysdeps.h
+++ b/sysdeps.h
@@ -582,18 +582,12 @@ static __inline__ int adb_thread_setname(const std::string& name) {
#ifdef __APPLE__
return pthread_setname_np(name.c_str());
#else
- const char *s = name.c_str();
-
- // pthread_setname_np fails rather than truncating long strings.
- const int max_task_comm_len = 16; // including the null terminator
- if (name.length() > (max_task_comm_len - 1)) {
- char buf[max_task_comm_len];
- strncpy(buf, name.c_str(), sizeof(buf) - 1);
- buf[sizeof(buf) - 1] = '\0';
- s = buf;
- }
-
- return pthread_setname_np(pthread_self(), s) ;
+ // Both bionic and glibc's pthread_setname_np fails rather than truncating long strings.
+ // glibc doesn't have strlcpy, so we have to fake it.
+ char buf[16]; // MAX_TASK_COMM_LEN, but that's not exported by the kernel headers.
+ strncpy(buf, name.c_str(), sizeof(buf) - 1);
+ buf[sizeof(buf) - 1] = '\0';
+ return pthread_setname_np(pthread_self(), buf);
#endif
}