diff --git a/src/lib/ares_private.h b/src/lib/ares_private.h index a6647430..1eecee36 100644 --- a/src/lib/ares_private.h +++ b/src/lib/ares_private.h @@ -558,4 +558,12 @@ size_t ares__count_digits(size_t n); size_t ares__count_hexdigits(size_t n); +# ifdef _MSC_VER +typedef __int64 ares_int64_t; +typedef unsigned __int64 ares_uint64_t; +# else +typedef long long ares_int64_t; +typedef unsigned long long ares_uint64_t; +# endif + #endif /* __ARES_PRIVATE_H */ diff --git a/src/lib/ares_process.c b/src/lib/ares_process.c index a196fccf..fa422048 100644 --- a/src/lib/ares_process.c +++ b/src/lib/ares_process.c @@ -106,7 +106,7 @@ static void server_set_good(struct server_state *server) ares_bool_t ares__timedout(const struct timeval *now, const struct timeval *check) { - time_t secs = (now->tv_sec - check->tv_sec); + ares_int64_t secs = ((ares_int64_t)now->tv_sec - (ares_int64_t)check->tv_sec); if (secs > 0) { return ARES_TRUE; /* yes, timed out */ @@ -116,7 +116,8 @@ ares_bool_t ares__timedout(const struct timeval *now, } /* if the full seconds were identical, check the sub second parts */ - return (now->tv_usec - check->tv_usec) >= 0 ? ARES_TRUE : ARES_FALSE; + return ((ares_int64_t)now->tv_usec - (ares_int64_t)check->tv_usec) >= 0 ? + ARES_TRUE : ARES_FALSE; } /* add the specific number of milliseconds to the time in the first argument */ diff --git a/src/lib/ares_rand.c b/src/lib/ares_rand.c index b4747d9f..15cfd71a 100644 --- a/src/lib/ares_rand.c +++ b/src/lib/ares_rand.c @@ -54,18 +54,12 @@ typedef struct ares_rand_rc4 { } ares_rand_rc4; -# ifdef _MSC_VER -typedef unsigned __int64 cares_u64; -# else -typedef unsigned long long cares_u64; -# endif - static unsigned int ares_u32_from_ptr(void *addr) { if (sizeof(void *) == 8) { - return (unsigned int)((((cares_u64)addr >> 32) & 0xFFFFFFFF) | - ((cares_u64)addr & 0xFFFFFFFF)); + return (unsigned int)((((ares_uint64_t)addr >> 32) & 0xFFFFFFFF) | + ((ares_uint64_t)addr & 0xFFFFFFFF)); } return (unsigned int)((size_t)addr & 0xFFFFFFFF); } diff --git a/src/lib/ares_timeout.c b/src/lib/ares_timeout.c index 123730fa..b02faf43 100644 --- a/src/lib/ares_timeout.c +++ b/src/lib/ares_timeout.c @@ -35,10 +35,11 @@ #include "ares_private.h" /* return time offset between now and (future) check, in milliseconds */ -static long timeoffset(const struct timeval *now, const struct timeval *check) +static ares_int64_t timeoffset(const struct timeval *now, + const struct timeval *check) { - return (check->tv_sec - now->tv_sec) * 1000 + - (check->tv_usec - now->tv_usec) / 1000; + return ((ares_int64_t)check->tv_sec - (ares_int64_t)now->tv_sec) * 1000 + + ((ares_int64_t)check->tv_usec - (ares_int64_t)now->tv_usec) / 1000; } struct timeval *ares_timeout(ares_channel_t *channel, struct timeval *maxtv, @@ -47,7 +48,7 @@ struct timeval *ares_timeout(ares_channel_t *channel, struct timeval *maxtv, const struct query *query; ares__slist_node_t *node; struct timeval now; - long offset; + ares_int64_t offset; /* The minimum timeout of all queries is always the first entry in * channel->queries_by_timeout */ @@ -65,12 +66,12 @@ struct timeval *ares_timeout(ares_channel_t *channel, struct timeval *maxtv, if (offset < 0) { offset = 0; } - if (offset > (long)INT_MAX) { + if (offset > INT_MAX) { offset = INT_MAX; } - tvbuf->tv_sec = offset / 1000; - tvbuf->tv_usec = (offset % 1000) * 1000; + tvbuf->tv_sec = (time_t)(offset / 1000); + tvbuf->tv_usec = (int)((offset % 1000) * 1000); if (maxtv == NULL) { return tvbuf;