Merge "Fix reference to out of scope local in adb_thread_setname."

am: b31ca1a64f

Change-Id: Idc5b3208b7868a2636b7c335c48db57dd48e8b83
This commit is contained in:
Elliott Hughes 2017-08-03 00:15:37 +00:00 committed by android-build-merger
commit 15d565bbca

View file

@ -582,18 +582,12 @@ static __inline__ int adb_thread_setname(const std::string& name) {
#ifdef __APPLE__ #ifdef __APPLE__
return pthread_setname_np(name.c_str()); return pthread_setname_np(name.c_str());
#else #else
const char *s = name.c_str(); // 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.
// pthread_setname_np fails rather than truncating long strings. char buf[16]; // MAX_TASK_COMM_LEN, but that's not exported by the kernel headers.
const int max_task_comm_len = 16; // including the null terminator strncpy(buf, name.c_str(), sizeof(buf) - 1);
if (name.length() > (max_task_comm_len - 1)) { buf[sizeof(buf) - 1] = '\0';
char buf[max_task_comm_len]; return pthread_setname_np(pthread_self(), buf);
strncpy(buf, name.c_str(), sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
s = buf;
}
return pthread_setname_np(pthread_self(), s) ;
#endif #endif
} }