From 54db98c220255737456b1311cb9534c9e95215c6 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 1 Feb 2007 01:42:13 +0000 Subject: [PATCH] compiler warning fix --- ares/ares_getnameinfo.c | 5 ++++- ares/ares_init.c | 6 +++--- ares/ares_mkquery.c | 2 +- ares/ares_send.c | 4 ++-- ares/inet_net_pton.c | 12 ++++++------ lib/ftp.c | 2 +- lib/mprintf.c | 10 +++++----- lib/url.c | 18 ++++++++++++++---- 8 files changed, 36 insertions(+), 23 deletions(-) diff --git a/ares/ares_getnameinfo.c b/ares/ares_getnameinfo.c index 71cf41d50..51e36fb10 100644 --- a/ares/ares_getnameinfo.c +++ b/ares/ares_getnameinfo.c @@ -357,6 +357,7 @@ static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags, static char *ares_striendstr(const char *s1, const char *s2) { const char *c1, *c2, *c1_begin; + int lo1, lo2; size_t s1_len = strlen(s1), s2_len = strlen(s2); /* If the substr is longer than the full str, it can't match */ @@ -369,7 +370,9 @@ static char *ares_striendstr(const char *s1, const char *s2) c2 = s2; while (c2 < s2+s2_len) { - if (tolower(*c1) != tolower(*c2)) + lo1 = tolower(*c1); + lo2 = tolower(*c2); + if (lo1 != lo2) return NULL; else { diff --git a/ares/ares_init.c b/ares/ares_init.c index e32633fde..e8371908a 100644 --- a/ares/ares_init.c +++ b/ares/ares_init.c @@ -181,7 +181,7 @@ int ares_init_options(ares_channel *channelptr, struct ares_options *options, */ gettimeofday(&tv, NULL); channel->next_id = (unsigned short) - (tv.tv_sec ^ tv.tv_usec ^ getpid()) & 0xffff; + ((tv.tv_sec ^ tv.tv_usec ^ getpid()) & 0xffff); channel->queries = NULL; @@ -893,7 +893,7 @@ static int config_sortlist(struct apattern **sortlist, int *nsort, sizeof(pat.addr.addr6))) > 0) { pat.type = PATTERN_CIDR; - pat.mask.bits = bits; + pat.mask.bits = (unsigned short)bits; pat.family = AF_INET6; if (!sortlist_alloc(sortlist, nsort, &pat)) return ARES_ENOMEM; @@ -903,7 +903,7 @@ static int config_sortlist(struct apattern **sortlist, int *nsort, sizeof(pat.addr.addr4))) > 0) { pat.type = PATTERN_CIDR; - pat.mask.bits = bits; + pat.mask.bits = (unsigned short)bits; pat.family = AF_INET; if (!sortlist_alloc(sortlist, nsort, &pat)) return ARES_ENOMEM; diff --git a/ares/ares_mkquery.c b/ares/ares_mkquery.c index e30abfc4f..11ce302b1 100644 --- a/ares/ares_mkquery.c +++ b/ares/ares_mkquery.c @@ -141,7 +141,7 @@ int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id, return ARES_EBADNAME; /* Encode the length and copy the data. */ - *q++ = len; + *q++ = (unsigned char)len; for (p = name; *p && *p != '.'; p++) { if (*p == '\\' && *(p + 1) != 0) diff --git a/ares/ares_send.c b/ares/ares_send.c index a279ee9ae..89efec089 100644 --- a/ares/ares_send.c +++ b/ares/ares_send.c @@ -79,8 +79,8 @@ void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen, /* Form the TCP query buffer by prepending qlen (as two * network-order bytes) to qbuf. */ - query->tcpbuf[0] = (qlen >> 8) & 0xff; - query->tcpbuf[1] = qlen & 0xff; + query->tcpbuf[0] = (unsigned char)((qlen >> 8) & 0xff); + query->tcpbuf[1] = (unsigned char)(qlen & 0xff); memcpy(query->tcpbuf + 2, qbuf, qlen); query->tcplen = qlen + 2; diff --git a/ares/inet_net_pton.c b/ares/inet_net_pton.c index ef96741a6..8c78a0b20 100644 --- a/ares/inet_net_pton.c +++ b/ares/inet_net_pton.c @@ -252,7 +252,7 @@ getv4(const char *src, unsigned char *dst, int *bitsp) if (ch == '.' || ch == '/') { if (dst - odst > 3) /* too many octets? */ return (0); - *dst++ = val; + *dst++ = (unsigned char)val; if (ch == '/') return (getbits(src, bitsp)); val = 0; @@ -265,7 +265,7 @@ getv4(const char *src, unsigned char *dst, int *bitsp) return (0); if (dst - odst > 3) /* too many octets? */ return (0); - *dst++ = val; + *dst++ = (unsigned char)val; return (1); } @@ -321,8 +321,8 @@ inet_net_pton_ipv6(const char *src, unsigned char *dst, size_t size) goto enoent; if (tp + NS_INT16SZ > endp) return (0); - *tp++ = (unsigned char) (val >> 8) & 0xff; - *tp++ = (unsigned char) val & 0xff; + *tp++ = (unsigned char)((val >> 8) & 0xff); + *tp++ = (unsigned char)(val & 0xff); saw_xdigit = 0; digits = 0; val = 0; @@ -342,8 +342,8 @@ inet_net_pton_ipv6(const char *src, unsigned char *dst, size_t size) if (saw_xdigit) { if (tp + NS_INT16SZ > endp) goto enoent; - *tp++ = (unsigned char) (val >> 8) & 0xff; - *tp++ = (unsigned char) val & 0xff; + *tp++ = (unsigned char)((val >> 8) & 0xff); + *tp++ = (unsigned char)(val & 0xff); } if (bits == -1) bits = 128; diff --git a/lib/ftp.c b/lib/ftp.c index 2ae973790..00aca12ee 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -3208,7 +3208,7 @@ static CURLcode ftp_nb_type(struct connectdata *conn, state(conn, newstate); /* keep track of our current transfer type */ - ftpc->transfertype = want; + ftpc->transfertype = (char)want; return CURLE_OK; } diff --git a/lib/mprintf.c b/lib/mprintf.c index 610395318..3224521b0 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -694,7 +694,7 @@ static int dprintf_formatf( else prec = -1; - alt = (p->flags & FLAGS_ALT)?TRUE:FALSE; + alt = (char)((p->flags & FLAGS_ALT)?TRUE:FALSE); switch (p->type) { case FORMAT_INT: @@ -734,14 +734,14 @@ static int dprintf_formatf( #ifdef ENABLE_64BIT if(p->flags & FLAGS_LONGLONG) { /* long long */ - is_neg = p->data.lnum < 0; + is_neg = (char)(p->data.lnum < 0); num = is_neg ? (- p->data.lnum) : p->data.lnum; } else #endif { signed_num = (long) num; - is_neg = signed_num < 0; + is_neg = (char)(signed_num < 0); num = is_neg ? (- signed_num) : signed_num; } goto number; @@ -944,9 +944,9 @@ static int dprintf_formatf( *fptr++ = 'l'; if (p->flags & FLAGS_FLOATE) - *fptr++ = p->flags&FLAGS_UPPER ? 'E':'e'; + *fptr++ = (char)((p->flags & FLAGS_UPPER) ? 'E':'e'); else if (p->flags & FLAGS_FLOATG) - *fptr++ = p->flags & FLAGS_UPPER ? 'G' : 'g'; + *fptr++ = (char)((p->flags & FLAGS_UPPER) ? 'G' : 'g'); else *fptr++ = 'f'; diff --git a/lib/url.c b/lib/url.c index 63c93f1b1..916d2a63c 100644 --- a/lib/url.c +++ b/lib/url.c @@ -375,19 +375,29 @@ CURLcode Curl_close(struct SessionHandle *data) /* create a connection cache of a private or multi type */ struct conncache *Curl_mk_connc(int type, - int amount) /* set -1 to use default */ + long amount) /* set -1 to use default */ { /* It is subject for debate how many default connections to have for a multi connection cache... */ - int default_amount = amount == -1? - ((type == CONNCACHE_PRIVATE)?5:10):amount; + struct conncache *c; + long default_amount; + + if (type == CONNCACHE_PRIVATE) { + default_amount = (amount < 0) ? 5 : amount; + } + else { + default_amount = (amount < 0) ? 10 : amount; + } c= calloc(sizeof(struct conncache), 1); if(!c) return NULL; - c->connects = calloc(sizeof(struct connectdata *), default_amount); + if ((size_t)(default_amount) > ((size_t)-1) / sizeof(struct connectdata *)) + default_amount = ((size_t)-1) / sizeof(struct connectdata *); + + c->connects = calloc(sizeof(struct connectdata *), (size_t)default_amount); if(!c->connects) { free(c); return NULL;