diff options
author | Elliott Hughes <enh@google.com> | 2017-08-02 13:22:38 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-08-02 20:34:06 +0000 |
commit | fda46ba4632b59d6054b67c6c7e79898839f785b (patch) | |
tree | 1fa877f4d21c4407c106810a0e3f6888d0992527 | |
parent | f6ca2255c022bd144f7bb16dff045746be283f40 (diff) | |
download | adb-fda46ba4632b59d6054b67c6c7e79898839f785b.tar.gz |
Fix reference to out of scope local in adb_thread_setname.
Bug: https://android-review.googlesource.com/#/c/168725/5/adb/sysdeps.h@639
Test: boots, adbd thread names look sane
Signed-off-by: Ivan Maidanski <i.maidanski@samsung.com>
Change-Id: Ib3bdf53658f3903de8f0a5688f7d77745e677c77
-rw-r--r-- | sysdeps.h | 18 |
1 files changed, 6 insertions, 12 deletions
@@ -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 } |