More explicit static casts for size_t to socklen_t

pull/14464/head
Yash Tibrewal 7 years ago
parent 4d46260dc5
commit 337373b91f
  1. 2
      test/core/end2end/goaway_server_test.cc
  2. 4
      test/core/iomgr/sockaddr_utils_test.cc
  3. 6
      test/core/iomgr/tcp_client_posix_test.cc
  4. 14
      test/core/iomgr/tcp_server_posix_test.cc
  5. 8
      test/core/iomgr/udp_server_test.cc

@ -82,7 +82,7 @@ static void my_resolve_address(const char* addr, const char* default_port,
sa->sin_family = AF_INET;
sa->sin_addr.s_addr = htonl(0x7f000001);
sa->sin_port = htons(static_cast<uint16_t>(g_resolve_port));
(*addrs)->addrs[0].len = sizeof(*sa);
(*addrs)->addrs[0].len = static_cast<socklen_t>(sizeof(*sa));
gpr_mu_unlock(&g_mu);
}
GRPC_CLOSURE_SCHED(on_done, error);

@ -40,7 +40,7 @@ static grpc_resolved_address make_addr4(const uint8_t* data, size_t data_len) {
GPR_ASSERT(data_len == sizeof(addr4->sin_addr.s_addr));
memcpy(&addr4->sin_addr.s_addr, data, data_len);
addr4->sin_port = htons(12345);
resolved_addr4.len = sizeof(struct sockaddr_in);
resolved_addr4.len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
return resolved_addr4;
}
@ -53,7 +53,7 @@ static grpc_resolved_address make_addr6(const uint8_t* data, size_t data_len) {
GPR_ASSERT(data_len == sizeof(addr6->sin6_addr.s6_addr));
memcpy(&addr6->sin6_addr.s6_addr, data, data_len);
addr6->sin6_port = htons(12345);
resolved_addr6.len = sizeof(struct sockaddr_in6);
resolved_addr6.len = static_cast<socklen_t>(sizeof(struct sockaddr_in6));
return resolved_addr6;
}

@ -89,7 +89,7 @@ void test_succeeds(void) {
gpr_log(GPR_DEBUG, "test_succeeds");
memset(&resolved_addr, 0, sizeof(resolved_addr));
resolved_addr.len = sizeof(struct sockaddr_in);
resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
/* create a dummy server */
@ -112,7 +112,7 @@ void test_succeeds(void) {
/* await the connection */
do {
resolved_addr.len = sizeof(addr);
resolved_addr.len = static_cast<socklen_t>(sizeof(addr));
r = accept(svr_fd, reinterpret_cast<struct sockaddr*>(addr),
reinterpret_cast<socklen_t*>(&resolved_addr.len));
} while (r == -1 && errno == EINTR);
@ -147,7 +147,7 @@ void test_fails(void) {
gpr_log(GPR_DEBUG, "test_fails");
memset(&resolved_addr, 0, sizeof(resolved_addr));
resolved_addr.len = sizeof(struct sockaddr_in);
resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
gpr_mu_lock(g_mu);

@ -188,7 +188,7 @@ static void test_no_op_with_port(void) {
LOG_TEST("test_no_op_with_port");
memset(&resolved_addr, 0, sizeof(resolved_addr));
resolved_addr.len = sizeof(struct sockaddr_in);
resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
int port = -1;
GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr, &port) ==
@ -209,7 +209,7 @@ static void test_no_op_with_port_and_start(void) {
int port = -1;
memset(&resolved_addr, 0, sizeof(resolved_addr));
resolved_addr.len = sizeof(struct sockaddr_in);
resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
GPR_ASSERT(grpc_tcp_server_add_port(s, &resolved_addr, &port) ==
GRPC_ERROR_NONE &&
@ -314,8 +314,8 @@ static void test_connect(size_t num_connects,
dst_addrs != nullptr ? "<specific>" : "::", test_dst_addrs);
memset(&resolved_addr, 0, sizeof(resolved_addr));
memset(&resolved_addr1, 0, sizeof(resolved_addr1));
resolved_addr.len = sizeof(struct sockaddr_storage);
resolved_addr1.len = sizeof(struct sockaddr_storage);
resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_storage));
resolved_addr1.len = static_cast<socklen_t>(sizeof(struct sockaddr_storage));
addr->ss_family = addr1->ss_family = AF_INET;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"grpc_tcp_server_add_port",
@ -387,7 +387,7 @@ static void test_connect(size_t num_connects,
size_t connect_num;
test_addr dst;
GPR_ASSERT(fd >= 0);
dst.addr.len = sizeof(dst.addr.addr);
dst.addr.len = static_cast<socklen_t>(sizeof(dst.addr.addr));
GPR_ASSERT(getsockname(fd, (struct sockaddr*)dst.addr.addr,
(socklen_t*)&dst.addr.len) == 0);
GPR_ASSERT(dst.addr.len <= sizeof(dst.addr.addr));
@ -460,10 +460,10 @@ int main(int argc, char** argv) {
continue;
} else if (ifa_it->ifa_addr->sa_family == AF_INET) {
dst_addrs->addrs[dst_addrs->naddrs].addr.len =
sizeof(struct sockaddr_in);
static_cast<socklen_t>(sizeof(struct sockaddr_in));
} else if (ifa_it->ifa_addr->sa_family == AF_INET6) {
dst_addrs->addrs[dst_addrs->naddrs].addr.len =
sizeof(struct sockaddr_in6);
static_cast<socklen_t>(sizeof(struct sockaddr_in6));
} else {
continue;
}

@ -210,7 +210,7 @@ static void test_no_op_with_port(void) {
LOG_TEST("test_no_op_with_port");
memset(&resolved_addr, 0, sizeof(resolved_addr));
resolved_addr.len = sizeof(struct sockaddr_in);
resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size,
snd_buf_size, &handler_factory));
@ -241,7 +241,7 @@ static void test_no_op_with_port_and_socket_factory(void) {
LOG_TEST("test_no_op_with_port_and_socket_factory");
memset(&resolved_addr, 0, sizeof(resolved_addr));
resolved_addr.len = sizeof(struct sockaddr_in);
resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size,
snd_buf_size, &handler_factory));
@ -268,7 +268,7 @@ static void test_no_op_with_port_and_start(void) {
LOG_TEST("test_no_op_with_port_and_start");
memset(&resolved_addr, 0, sizeof(resolved_addr));
resolved_addr.len = sizeof(struct sockaddr_in);
resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size,
snd_buf_size, &handler_factory));
@ -301,7 +301,7 @@ static void test_receive(int number_of_clients) {
g_number_of_orphan_calls = 0;
memset(&resolved_addr, 0, sizeof(resolved_addr));
resolved_addr.len = sizeof(struct sockaddr_storage);
resolved_addr.len = static_cast<socklen_t>(sizeof(struct sockaddr_storage));
addr->ss_family = AF_INET;
GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, rcv_buf_size,
snd_buf_size, &handler_factory));

Loading…
Cancel
Save