diff options
| author | Lioncache <mai.iam2048@gmail.com> | 2023-12-18 10:48:42 -0500 |
|---|---|---|
| committer | Lioncache <mai.iam2048@gmail.com> | 2023-12-18 13:08:57 -0500 |
| commit | dc85194fac9f0527a15cf147fe75a15a7e573a1e (patch) | |
| tree | 4eb0395d726763aa4bb30587b8fc1567200decea /Source/Core | |
| parent | 1764b13423059a06f718687c55d44bc20cc3330b (diff) | |
Common/TraversalServer: Make use of fmt over sprintf where applicable
Resolves some deprecation warnings on macOS. This is better anyway, given fmt
has generic type formatting.
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Common/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | Source/Core/Common/TraversalServer.cpp | 10 |
2 files changed, 7 insertions, 5 deletions
diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index a4a761276b..9f8702659b 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -329,7 +329,7 @@ endif() if(UNIX) # Posix networking code needs to be fixed for Windows add_executable(traversal_server TraversalServer.cpp) - target_link_libraries(traversal_server PRIVATE common) + target_link_libraries(traversal_server PRIVATE common fmt::fmt) if(SYSTEMD_FOUND) target_link_libraries(traversal_server PRIVATE ${SYSTEMD_LIBRARIES}) endif() diff --git a/Source/Core/Common/TraversalServer.cpp b/Source/Core/Common/TraversalServer.cpp index 5991de9e99..784ef9d743 100644 --- a/Source/Core/Common/TraversalServer.cpp +++ b/Source/Core/Common/TraversalServer.cpp @@ -18,6 +18,8 @@ #include <utility> #include <vector> +#include <fmt/format.h> + #ifdef HAVE_LIBSYSTEMD #include <systemd/sd-daemon.h> #endif @@ -177,17 +179,17 @@ static sockaddr_in6 MakeSinAddr(const Common::TraversalInetAddress& addr) static void GetRandomHostId(Common::TraversalHostId* hostId) { - char buf[9]; + char buf[9]{}; const u32 num = Common::Random::GenerateValue<u32>(); - sprintf(buf, "%08x", num); + fmt::format_to_n(buf, sizeof(buf) - 1, "{:08x}", num); memcpy(hostId->data(), buf, 8); } static const char* SenderName(sockaddr_in6* addr) { - static char buf[INET6_ADDRSTRLEN + 10]; + static char buf[INET6_ADDRSTRLEN + 10]{}; inet_ntop(PF_INET6, &addr->sin6_addr, buf, sizeof(buf)); - sprintf(buf + strlen(buf), ":%d", ntohs(addr->sin6_port)); + fmt::format_to(buf + strlen(buf), ":{}", ntohs(addr->sin6_port)); return buf; } |
