zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.71k stars 2.35k forks source link

deprecate sprint and replace with snprintf #4494

Closed sphaero closed 1 year ago

sphaero commented 1 year ago

Problem: Latest OSX deprecates using sprint resulting is failure to build Fix by switching to snprint.

As tried by #4481 and fixing #4478

bluca commented 1 year ago

can you fix the formatting?

--- a/src/tcp_address.cpp
+++ b/src/tcp_address.cpp
@@ -129,7 +129,8 @@ static std::string make_address_string (const char *hbuf_,
     pos += hbuf_len;
     memcpy (pos, ipv6_suffix_, sizeof ipv6_suffix_ - 1);
     pos += sizeof ipv6_suffix_ - 1;
-    pos += snprintf (pos, max_port_str_length * sizeof(char), "%d", ntohs (port_));
+    pos +=
+      snprintf (pos, max_port_str_length * sizeof (char), "%d", ntohs (port_));
     return std::string (buf, pos - buf);
 }

diff --git a/src/udp_engine.cpp b/src/udp_engine.cpp
index 4d471a8..47f1359 100644
--- a/src/udp_engine.cpp
+++ b/src/udp_engine.cpp
@@ -367,8 +367,8 @@ void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg_,
     const char *const name = inet_ntoa (addr_->sin_addr);

     char port[6];
-    const int port_len =
-      snprintf (port, 6 * sizeof(char), "%d", static_cast<int> (ntohs (addr_->sin_port)));
+    const int port_len = snprintf (port, 6 * sizeof (char), "%d",
+                                   static_cast<int> (ntohs (addr_->sin_port)));
     zmq_assert (port_len > 0);

     const size_t name_len = strlen (name);
diff --git a/tests/testutil.cpp b/tests/testutil.cpp
index 74d139f..a521d57 100644
--- a/tests/testutil.cpp
+++ b/tests/testutil.cpp
@@ -518,16 +518,15 @@ fd_t bind_socket_resolve_port (const char *address_,
         addr_len = sizeof (struct sockaddr_storage);
         TEST_ASSERT_SUCCESS_RAW_ERRNO (
           getsockname (s_pre, (struct sockaddr *) &addr, &addr_len));
-        snprintf (my_endpoint_, 6 + strlen(address_) + 6 * sizeof(char),
-                  "%s://%s:%u",
-                 protocol_ == IPPROTO_TCP   ? "tcp"
-                 : protocol_ == IPPROTO_UDP ? "udp"
-                 : protocol_ == IPPROTO_WSS ? "wss"
-                                            : "ws",
-                 address_,
-                 af_ == AF_INET
-                   ? ntohs ((*(struct sockaddr_in *) &addr).sin_port)
-                   : ntohs ((*(struct sockaddr_in6 *) &addr).sin6_port));
+        snprintf (
+          my_endpoint_, 6 + strlen (address_) + 6 * sizeof (char), "%s://%s:%u",
+          protocol_ == IPPROTO_TCP   ? "tcp"
+          : protocol_ == IPPROTO_UDP ? "udp"
+          : protocol_ == IPPROTO_WSS ? "wss"
+                                     : "ws",
+          address_,
+          af_ == AF_INET ? ntohs ((*(struct sockaddr_in *) &addr).sin_port)
+                         : ntohs ((*(struct sockaddr_in6 *) &addr).sin6_port));
     }

     return s_pre;
sphaero commented 1 year ago

I'll fix if I can get succesful tests. I'm also still missing one sprintf. (Disclaimer; I don't have any OSX machines so I'm really dependent on CI)

Not sure what's happening with CI tests now as I'm hardly getting any output. I might still be having the max size wrong though

sphaero commented 1 year ago

Not sure why it says it's not successful. All tests seem fine?

bluca commented 1 year ago

Not sure why it says it's not successful. All tests seem fine?

there are some failures, but it's just the usual flaky tests

sphaero commented 1 year ago

Ok, but where do you see those failures. I only see green checkmarks

bluca commented 1 year ago

You don't see these in the list?

Screenshot from 2023-01-25 09-58-13

sphaero commented 1 year ago

Aargh, my browser is hiding the scrollbar so I never noticed I can scroll down.