From 30935ef0bcdc7703eb2199e3fc5095198497e889 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Fri, 31 May 2019 05:55:07 +0000 Subject: [PATCH] Fix problem with r362192 The string returned only sometimes ends in NULL. Explicitly check for the NULL and pop off the NULL if it is there. llvm-svn: 362194 --- lldb/source/Host/posix/DomainSocket.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lldb/source/Host/posix/DomainSocket.cpp b/lldb/source/Host/posix/DomainSocket.cpp index 2710213..27872f4 100644 --- a/lldb/source/Host/posix/DomainSocket.cpp +++ b/lldb/source/Host/posix/DomainSocket.cpp @@ -132,11 +132,14 @@ std::string DomainSocket::GetSocketName() const { saddr_un.sun_family = AF_UNIX; socklen_t sock_addr_len = sizeof(struct sockaddr_un); if (::getpeername(m_socket, (struct sockaddr *)&saddr_un, &sock_addr_len) == - 0) - return std::string(saddr_un.sun_path + GetNameOffset(), - sock_addr_len - - offsetof(struct sockaddr_un, sun_path) - - GetNameOffset() - 1); + 0) { + std::string name(saddr_un.sun_path + GetNameOffset(), + sock_addr_len - + offsetof(struct sockaddr_un, sun_path) - + GetNameOffset()); + if (name.back() == '\0') name.pop_back(); + return name; + } } return ""; } -- 2.7.4