From 716d5817dcf828222bf2c7bc166ea7b24c2d515b Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 8 Oct 2009 00:02:32 +0000 Subject: [PATCH] Fix compiler warning: addition result could be truncated before cast to bigger sized type --- ares__get_hostent.c | 2 +- ares_expand_name.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ares__get_hostent.c b/ares__get_hostent.c index 8402714..d98af92 100644 --- a/ares__get_hostent.c +++ b/ares__get_hostent.c @@ -194,7 +194,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host) memcpy(hostent->h_addr_list[0], &addr6, addrlen); /* Copy aliases. */ - hostent->h_aliases = malloc((naliases + 1) * sizeof(char *)); + hostent->h_aliases = malloc((((size_t)naliases) + 1) * sizeof(char *)); if (!hostent->h_aliases) break; alias = hostent->h_aliases; diff --git a/ares_expand_name.c b/ares_expand_name.c index b0af474..a1556e9 100644 --- a/ares_expand_name.c +++ b/ares_expand_name.c @@ -71,10 +71,10 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf, const unsigned char *p; len = name_length(encoded, abuf, alen); - if (len == -1) + if (len < 0) return ARES_EBADNAME; - *s = malloc(len + 1); + *s = malloc(((size_t)len) + 1); if (!*s) return ARES_ENOMEM; q = *s; -- 2.7.4