diff options
author | Yang Tse <yangsita@gmail.com> | 2009-06-12 02:41:16 +0000 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2009-06-12 02:41:16 +0000 |
commit | 4ea513cc387c0a67c861a87aea01e6d1cac4854c (patch) | |
tree | bd32a99caf08d3945f215cd0a0e179b8a2f3d881 /lib | |
parent | 3ca0b9bb47f015c0de7379da46d10948e0637302 (diff) |
fix compiler warning
Diffstat (limited to 'lib')
-rw-r--r-- | lib/easy.c | 2 | ||||
-rw-r--r-- | lib/multi.c | 2 | ||||
-rw-r--r-- | lib/url.c | 18 |
3 files changed, 13 insertions, 9 deletions
diff --git a/lib/easy.c b/lib/easy.c index 7701ce8e5..70aa5a097 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -544,7 +544,7 @@ CURLcode curl_easy_perform(CURL *curl) if(!data->state.connc) { /* oops, no connection cache, make one up */ - data->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE, -1); + data->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE, -1L); if(!data->state.connc) return CURLE_OUT_OF_MEMORY; } diff --git a/lib/multi.c b/lib/multi.c index 25c8b9a9c..2c5b6d94d 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -382,7 +382,7 @@ CURLM *curl_multi_init(void) return NULL; } - multi->connc = Curl_mk_connc(CONNCACHE_MULTI, -1); + multi->connc = Curl_mk_connc(CONNCACHE_MULTI, -1L); if(!multi->connc) { Curl_hash_destroy(multi->sockhash); Curl_hash_destroy(multi->hostcache); @@ -531,22 +531,23 @@ struct conncache *Curl_mk_connc(int type, struct conncache *c; long default_amount; + long max_amount = (long)(((size_t)INT_MAX) / sizeof(struct connectdata *)); if(type == CONNCACHE_PRIVATE) { - default_amount = (amount < 0) ? 5 : amount; + default_amount = (amount < 1L) ? 5L : amount; } else { - default_amount = (amount < 0) ? 10 : amount; + default_amount = (amount < 1L) ? 10L : amount; } - c= calloc(sizeof(struct conncache), 1); + if(default_amount > max_amount) + default_amount = max_amount; + + c = calloc(1, sizeof(struct conncache)); if(!c) return NULL; - 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); + c->connects = calloc((size_t)default_amount, sizeof(struct connectdata *)); if(!c->connects) { free(c); return NULL; @@ -564,6 +565,7 @@ CURLcode Curl_ch_connc(struct SessionHandle *data, { long i; struct connectdata **newptr; + long max_amount = (long)(((size_t)INT_MAX) / sizeof(struct connectdata *)); if(newamount < 1) newamount = 1; /* we better have at least one entry */ @@ -596,6 +598,8 @@ CURLcode Curl_ch_connc(struct SessionHandle *data, data->state.lastconnect = -1; } if(newamount > 0) { + if(newamount > max_amount) + newamount = max_amount; newptr = realloc(c->connects, sizeof(struct connectdata *) * newamount); if(!newptr) /* we closed a few connections in vain, but so what? */ |