From 73f3d7f59b1e7c6509f4e3af4f6cf6a2d7dd6818 Mon Sep 17 00:00:00 2001 From: Schuyler Goodman Date: Thu, 29 Oct 2020 09:33:48 -0700 Subject: [PATCH] Fix msbuild warnings C4005, C4242 (#2619) * Fix msbuild typecast warnings * Better way to fix C4005 * Fix formatting errors and invalid USHORT cast Co-authored-by: Schuyler Goodman Co-authored-by: Jack Gerrits --- vowpalwabbit/allreduce_sockets.cc | 7 +++---- vowpalwabbit/v_array.h | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/vowpalwabbit/allreduce_sockets.cc b/vowpalwabbit/allreduce_sockets.cc index 22c993ece26..bd00fd756ec 100644 --- a/vowpalwabbit/allreduce_sockets.cc +++ b/vowpalwabbit/allreduce_sockets.cc @@ -41,7 +41,7 @@ socket_t AllReduceSockets::sock_connect(const uint32_t ip, const int port) sockaddr_in far_end; far_end.sin_family = AF_INET; - far_end.sin_port = port; + far_end.sin_port = (u_short)port; far_end.sin_addr = *(in_addr*)&ip; memset(&far_end.sin_zero, '\0', 8); @@ -56,8 +56,7 @@ socket_t AllReduceSockets::sock_connect(const uint32_t ip, const int port) if (getnameinfo((sockaddr*)&far_end, sizeof(sockaddr), hostname, NI_MAXHOST, servInfo, NI_MAXSERV, NI_NUMERICSERV)) THROWERRNO("getnameinfo(" << dotted_quad << ")"); - if (!quiet) - cerr << "connecting to " << dotted_quad << " = " << hostname << ':' << ntohs(port) << endl; + if (!quiet) cerr << "connecting to " << dotted_quad << " = " << hostname << ':' << ntohs((u_short)port) << endl; } size_t count = 0; @@ -132,7 +131,7 @@ void AllReduceSockets::all_reduce_init() uint32_t master_ip = *((uint32_t*)master->h_addr); - socket_t master_sock = sock_connect(master_ip, htons(port)); + socket_t master_sock = sock_connect(master_ip, htons((u_short)port)); if (send(master_sock, (const char*)&unique_id, sizeof(unique_id), 0) < (int)sizeof(unique_id)) { THROW("write unique_id=" << unique_id << " to span server failed"); diff --git a/vowpalwabbit/v_array.h b/vowpalwabbit/v_array.h index 28633a48ce5..6685517e790 100644 --- a/vowpalwabbit/v_array.h +++ b/vowpalwabbit/v_array.h @@ -3,7 +3,10 @@ // license as described in the file LICENSE. #pragma once -#define NOMINMAX +#ifndef NOMINMAX +# define NOMINMAX +#endif + #include #include #include