[Lldb-commits] [lldb] r362194 - Fix problem with r362192

Richard Trieu via lldb-commits lldb-commits at lists.llvm.org
Thu May 30 22:55:07 PDT 2019


Author: rtrieu
Date: Thu May 30 22:55:07 2019
New Revision: 362194

URL: http://llvm.org/viewvc/llvm-project?rev=362194&view=rev
Log:
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.

Modified:
    lldb/trunk/source/Host/posix/DomainSocket.cpp

Modified: lldb/trunk/source/Host/posix/DomainSocket.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/DomainSocket.cpp?rev=362194&r1=362193&r2=362194&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/DomainSocket.cpp (original)
+++ lldb/trunk/source/Host/posix/DomainSocket.cpp Thu May 30 22:55:07 2019
@@ -132,11 +132,14 @@ std::string DomainSocket::GetSocketName(
     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 "";
 }




More information about the lldb-commits mailing list