From 41b8a1bfd077ed0035d6bea42c70b1156b919dd5 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 1 Dec 2010 23:36:19 +0100 Subject: [PATCH] fix compiler warning: conversion may lose significant bits --- ares_init.c | 7 ++++--- ares_nowarn.c | 18 ++++++++++++++++++ ares_nowarn.h | 2 ++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ares_init.c b/ares_init.c index eb1719ab..3351bcf1 100644 --- a/ares_init.c +++ b/ares_init.c @@ -67,6 +67,7 @@ #include "ares.h" #include "inet_net_pton.h" #include "ares_library_init.h" +#include "ares_nowarn.h" #include "ares_private.h" #ifdef ANDROID @@ -1400,13 +1401,13 @@ static int set_options(ares_channel channel, const char *str) q++; val = try_option(p, q, "ndots:"); if (val && channel->ndots == -1) - channel->ndots = (int)strtol(val, NULL, 10); + channel->ndots = aresx_sltosi(strtol(val, NULL, 10)); val = try_option(p, q, "retrans:"); if (val && channel->timeout == -1) - channel->timeout = (int)strtol(val, NULL, 10); + channel->timeout = aresx_sltosi(strtol(val, NULL, 10)); val = try_option(p, q, "retry:"); if (val && channel->tries == -1) - channel->tries = (int)strtol(val, NULL, 10); + channel->tries = aresx_sltosi(strtol(val, NULL, 10)); val = try_option(p, q, "rotate"); if (val && channel->rotate == -1) channel->rotate = 1; diff --git a/ares_nowarn.c b/ares_nowarn.c index 4eee25fd..ed84ade4 100644 --- a/ares_nowarn.c +++ b/ares_nowarn.c @@ -50,3 +50,21 @@ int aresx_uztosi(size_t uznum) # pragma warning(pop) #endif } + +/* +** signed long to signed int +*/ + +int aresx_sltosi(long slnum) +{ +#ifdef __INTEL_COMPILER +# pragma warning(push) +# pragma warning(disable:810) /* conversion may lose significant bits */ +#endif + + return (int)(slnum & (long) CARES_MASK_SINT); + +#ifdef __INTEL_COMPILER +# pragma warning(pop) +#endif +} diff --git a/ares_nowarn.h b/ares_nowarn.h index 2b407de2..fb804951 100644 --- a/ares_nowarn.h +++ b/ares_nowarn.h @@ -19,4 +19,6 @@ int aresx_uztosi(size_t uznum); +int aresx_sltosi(long slnum); + #endif /* HEADER_CARES_NOWARN_H */