[Lldb-commits] [lldb] r349495 - Fix the "dangerous use of tempnam" warning in Host/SocketTest.cpp

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 18 07:33:51 PST 2018


Author: labath
Date: Tue Dec 18 07:33:50 2018
New Revision: 349495

URL: http://llvm.org/viewvc/llvm-project?rev=349495&view=rev
Log:
Fix the "dangerous use of tempnam" warning in Host/SocketTest.cpp

instead, create a unique temporary directory, and place the socket file
there.

Modified:
    lldb/trunk/unittests/Host/SocketTest.cpp

Modified: lldb/trunk/unittests/Host/SocketTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/SocketTest.cpp?rev=349495&r1=349494&r2=349495&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/SocketTest.cpp (original)
+++ lldb/trunk/unittests/Host/SocketTest.cpp Tue Dec 18 07:33:50 2018
@@ -17,6 +17,8 @@
 #include "lldb/Host/Socket.h"
 #include "lldb/Host/common/TCPSocket.h"
 #include "lldb/Host/common/UDPSocket.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 
 #ifndef LLDB_DISABLE_POSIX
 #include "lldb/Host/posix/DomainSocket.h"
@@ -41,7 +43,6 @@ public:
 
 protected:
   static void AcceptThread(Socket *listen_socket,
-                           const char *listen_remote_address,
                            bool child_processes_inherit, Socket **accept_socket,
                            Status *error) {
     *error = listen_socket->Accept(*accept_socket);
@@ -49,7 +50,7 @@ protected:
 
   template <typename SocketType>
   void CreateConnectedSockets(
-      const char *listen_remote_address,
+      llvm::StringRef listen_remote_address,
       const std::function<std::string(const SocketType &)> &get_connect_addr,
       std::unique_ptr<SocketType> *a_up, std::unique_ptr<SocketType> *b_up) {
     bool child_processes_inherit = false;
@@ -64,8 +65,8 @@ protected:
     Status accept_error;
     Socket *accept_socket;
     std::thread accept_thread(AcceptThread, listen_socket_up.get(),
-                              listen_remote_address, child_processes_inherit,
-                              &accept_socket, &accept_error);
+                              child_processes_inherit, &accept_socket,
+                              &accept_error);
 
     std::string connect_remote_address = get_connect_addr(*listen_socket_up);
     std::unique_ptr<SocketType> connect_socket_up(
@@ -158,15 +159,15 @@ TEST_F(SocketTest, DecodeHostAndPort) {
 
 #ifndef LLDB_DISABLE_POSIX
 TEST_F(SocketTest, DomainListenConnectAccept) {
-  char *file_name_str = tempnam(nullptr, nullptr);
-  EXPECT_NE(nullptr, file_name_str);
-  const std::string file_name(file_name_str);
-  free(file_name_str);
+  llvm::SmallString<64> Path;
+  std::error_code EC = llvm::sys::fs::createUniqueDirectory("DomainListenConnectAccept", Path);
+  ASSERT_FALSE(EC);
+  llvm::sys::path::append(Path, "test");
 
   std::unique_ptr<DomainSocket> socket_a_up;
   std::unique_ptr<DomainSocket> socket_b_up;
   CreateConnectedSockets<DomainSocket>(
-      file_name.c_str(), [=](const DomainSocket &) { return file_name; },
+      Path, [=](const DomainSocket &) { return Path.str().str(); },
       &socket_a_up, &socket_b_up);
 }
 #endif




More information about the lldb-commits mailing list