[Lldb-commits] [lldb] 1c7e407 - [lldb] Fix warning: 'sprintf' is deprecated in RNBSocketTest
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Sat Nov 30 17:40:54 PST 2024
Author: Jonas Devlieghere
Date: 2024-11-30T17:40:00-08:00
New Revision: 1c7e4074b1efe7c3c9110f1d116b16f50fce9c88
URL: https://github.com/llvm/llvm-project/commit/1c7e4074b1efe7c3c9110f1d116b16f50fce9c88
DIFF: https://github.com/llvm/llvm-project/commit/1c7e4074b1efe7c3c9110f1d116b16f50fce9c88.diff
LOG: [lldb] Fix warning: 'sprintf' is deprecated in RNBSocketTest
Fixes warning: 'sprintf' is deprecated: This function is provided for
compatibility reasons only. Due to security concerns inherent in the
design of sprintf(3), it is highly recommended that you use snprintf(3)
instead.
Added:
Modified:
lldb/unittests/debugserver/RNBSocketTest.cpp
Removed:
################################################################################
diff --git a/lldb/unittests/debugserver/RNBSocketTest.cpp b/lldb/unittests/debugserver/RNBSocketTest.cpp
index 342ae10979973c..48f747b09587fe 100644
--- a/lldb/unittests/debugserver/RNBSocketTest.cpp
+++ b/lldb/unittests/debugserver/RNBSocketTest.cpp
@@ -26,8 +26,8 @@ std::string goodbye = "Goodbye!";
static void ServerCallbackv4(const void *baton, in_port_t port) {
auto child_pid = fork();
if (child_pid == 0) {
- char addr_buffer[256];
- sprintf(addr_buffer, "%s:%d", (const char *)baton, port);
+ std::string addr_buffer =
+ llvm::formatv("{0}:{1}", (const char *)baton, port).str();
llvm::Expected<std::unique_ptr<Socket>> socket_or_err =
Socket::TcpConnect(addr_buffer);
ASSERT_THAT_EXPECTED(socket_or_err, llvm::Succeeded());
@@ -59,15 +59,12 @@ void TestSocketListen(const char *addr) {
if (addresses.size() == 0)
return;
- char addr_wrap[256];
- if (addresses.front().GetFamily() == AF_INET6)
- sprintf(addr_wrap, "[%s]", addr);
- else
- sprintf(addr_wrap, "%s", addr);
+ const char *fmt = addresses.front().GetFamily() == AF_INET6 ? "[{0}]" : "{0}";
+ std::string addr_wrap = llvm::formatv(fmt, addr).str();
RNBSocket server_socket;
- auto result =
- server_socket.Listen(addr, 0, ServerCallbackv4, (const void *)addr_wrap);
+ auto result = server_socket.Listen(addr, 0, ServerCallbackv4,
+ (const void *)addr_wrap.c_str());
ASSERT_TRUE(result == rnb_success);
result = server_socket.Write(hello.c_str(), hello.length());
ASSERT_TRUE(result == rnb_success);
@@ -94,11 +91,9 @@ void TestSocketConnect(const char *addr) {
if (addresses.size() == 0)
return;
- char addr_wrap[256];
- if (addresses.front().GetFamily() == AF_INET6)
- sprintf(addr_wrap, "[%s]:0", addr);
- else
- sprintf(addr_wrap, "%s:0", addr);
+ const char *fmt =
+ addresses.front().GetFamily() == AF_INET6 ? "[{0}]:0" : "{0}:0";
+ std::string addr_wrap = llvm::formatv(fmt, addr).str();
Socket *server_socket;
llvm::Expected<std::unique_ptr<Socket>> socket_or_err =
More information about the lldb-commits
mailing list