summaryrefslogtreecommitdiff
path: root/lldb/unittests
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2018-12-18 15:33:50 +0000
committerPavel Labath <pavel@labath.sk>2018-12-18 15:33:50 +0000
commitdba7efdd1decc338560b33af1ff1d7632b6b843e (patch)
tree2d734cd7bfcf4b2ffa18fa58875de9e082f53c0b /lldb/unittests
parent8888a9d6c7ceb640146779521149b68c226e3263 (diff)
Fix the "dangerous use of tempnam" warning in Host/SocketTest.cpp
instead, create a unique temporary directory, and place the socket file there.
Diffstat (limited to 'lldb/unittests')
-rw-r--r--lldb/unittests/Host/SocketTest.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/lldb/unittests/Host/SocketTest.cpp b/lldb/unittests/Host/SocketTest.cpp
index 59f59fc0ada..e7e71386144 100644
--- a/lldb/unittests/Host/SocketTest.cpp
+++ b/lldb/unittests/Host/SocketTest.cpp
@@ -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