From 38b69b7269d4abbc75f34b8ab38d7bdab4ad91ab Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 14 Jun 2012 21:19:48 +0200 Subject: [PATCH] Kill compiler warning --- ares_init.c | 4 ++-- ares_nowarn.c | 21 ++++++++++++++++++++- ares_nowarn.h | 4 +++- ares_process.c | 10 +++++----- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/ares_init.c b/ares_init.c index ccdc07a..f9eb054 100644 --- a/ares_init.c +++ b/ares_init.c @@ -355,8 +355,8 @@ int ares_save_options(ares_channel channel, struct ares_options *options, options->timeout = channel->timeout; options->tries = channel->tries; options->ndots = channel->ndots; - options->udp_port = (unsigned short)ntohs(channel->udp_port); - options->tcp_port = (unsigned short)ntohs(channel->tcp_port); + options->udp_port = ntohs(aresx_sitous(channel->udp_port)); + options->tcp_port = ntohs(aresx_sitous(channel->tcp_port)); options->sock_state_cb = channel->sock_state_cb; options->sock_state_cb_data = channel->sock_state_cb_data; diff --git a/ares_nowarn.c b/ares_nowarn.c index 0056bb8..dc33bcf 100644 --- a/ares_nowarn.c +++ b/ares_nowarn.c @@ -1,5 +1,5 @@ -/* Copyright (C) 2010-2011 by Daniel Stenberg +/* Copyright (C) 2010-2012 by Daniel Stenberg * * Permission to use, copy, modify, and distribute this * software and its documentation for any purpose and without @@ -214,6 +214,25 @@ unsigned int aresx_sztoui(ssize_t sznum) #endif } +/* +** signed int to unsigned short +*/ + +unsigned short aresx_sitous(int sinum) +{ +#ifdef __INTEL_COMPILER +# pragma warning(push) +# pragma warning(disable:810) /* conversion may lose significant bits */ +#endif + + DEBUGASSERT(sinum >= 0); + return (unsigned short)(sinum & (int) CARES_MASK_USHORT); + +#ifdef __INTEL_COMPILER +# pragma warning(pop) +#endif +} + #if defined(__INTEL_COMPILER) && defined(__unix__) int aresx_FD_ISSET(int fd, fd_set *fdset) diff --git a/ares_nowarn.h b/ares_nowarn.h index c593e45..9b76d66 100644 --- a/ares_nowarn.h +++ b/ares_nowarn.h @@ -2,7 +2,7 @@ #define HEADER_CARES_NOWARN_H -/* Copyright (C) 2010-2011 by Daniel Stenberg +/* Copyright (C) 2010-2012 by Daniel Stenberg * * Permission to use, copy, modify, and distribute this * software and its documentation for any purpose and without @@ -29,6 +29,8 @@ int aresx_sztosi(ssize_t sznum); unsigned int aresx_sztoui(ssize_t sznum); +unsigned short aresx_sitous(int sinum); + #if defined(__INTEL_COMPILER) && defined(__unix__) int aresx_FD_ISSET(int fd, fd_set *fdset); diff --git a/ares_process.c b/ares_process.c index 5de1ae6..79a999f 100644 --- a/ares_process.c +++ b/ares_process.c @@ -1,6 +1,6 @@ /* Copyright 1998 by the Massachusetts Institute of Technology. - * Copyright (C) 2004-2011 by Daniel Stenberg + * Copyright (C) 2004-2012 by Daniel Stenberg * * Permission to use, copy, modify, and distribute this * software and its documentation for any purpose and without @@ -946,7 +946,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server) salen = sizeof(saddr.sa4); memset(sa, 0, salen); saddr.sa4.sin_family = AF_INET; - saddr.sa4.sin_port = (unsigned short)(channel->tcp_port & 0xffff); + saddr.sa4.sin_port = aresx_sitous(channel->tcp_port); memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4, sizeof(server->addr.addrV4)); break; @@ -955,7 +955,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server) salen = sizeof(saddr.sa6); memset(sa, 0, salen); saddr.sa6.sin6_family = AF_INET6; - saddr.sa6.sin6_port = (unsigned short)(channel->tcp_port & 0xffff); + saddr.sa6.sin6_port = aresx_sitous(channel->tcp_port); memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6, sizeof(server->addr.addrV6)); break; @@ -1038,7 +1038,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server) salen = sizeof(saddr.sa4); memset(sa, 0, salen); saddr.sa4.sin_family = AF_INET; - saddr.sa4.sin_port = (unsigned short)(channel->udp_port & 0xffff); + saddr.sa4.sin_port = aresx_sitous(channel->udp_port); memcpy(&saddr.sa4.sin_addr, &server->addr.addrV4, sizeof(server->addr.addrV4)); break; @@ -1047,7 +1047,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server) salen = sizeof(saddr.sa6); memset(sa, 0, salen); saddr.sa6.sin6_family = AF_INET6; - saddr.sa6.sin6_port = (unsigned short)(channel->udp_port & 0xffff); + saddr.sa6.sin6_port = aresx_sitous(channel->udp_port); memcpy(&saddr.sa6.sin6_addr, &server->addr.addrV6, sizeof(server->addr.addrV6)); break;