From 367ea4a68bf510ec2bb3d30dee73be3fb6b2eca5 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 25 Apr 2024 11:07:44 +0200 Subject: [PATCH] #13481 --- lib/altsvc.c | 12 ++++++------ lib/altsvc.h | 2 +- lib/bufq.c | 10 +++++----- lib/cf-https-connect.c | 6 ++++-- lib/cf-socket.c | 2 +- lib/cfilters.c | 2 +- lib/content_encoding.c | 7 ++++--- lib/cookie.c | 14 +++++++------- lib/curl_ntlm_core.c | 16 ++++++++-------- lib/curl_trc.c | 17 +++++++++-------- lib/doh.c | 16 ++++++++-------- lib/dynhds.c | 2 +- lib/easy.c | 2 +- lib/escape.c | 13 +++++++------ lib/file.c | 13 ++++++++----- lib/formdata.c | 11 ++++++----- lib/ftp.c | 22 +++++++++++----------- lib/getinfo.c | 8 ++++---- lib/gopher.c | 6 +++--- lib/hash.c | 10 +++++----- lib/hash.h | 2 +- lib/headers.c | 4 ++-- lib/hostip.c | 16 ++++++++-------- lib/http.c | 11 ++++++----- lib/http1.c | 10 +++++----- lib/http_aws_sigv4.c | 11 ++++++----- lib/http_chunks.c | 6 +++--- lib/http_digest.c | 2 +- lib/if2ip.c | 3 ++- lib/imap.c | 12 ++++++------ lib/mime.c | 17 +++++++++-------- lib/mqtt.c | 28 ++++++++++++++-------------- lib/multi.c | 19 ++++++++++--------- lib/noproxy.c | 10 +++++----- lib/pingpong.c | 6 +++--- lib/pop3.c | 8 ++++---- lib/rand.c | 4 ++-- lib/request.c | 2 +- lib/rtsp.c | 6 ++++-- lib/select.c | 2 +- lib/sendf.c | 6 +++--- lib/setopt.c | 2 +- lib/smb.c | 8 ++++---- lib/smtp.c | 4 ++-- lib/socks.c | 16 ++++++++-------- lib/telnet.c | 23 ++++++++++++----------- lib/tftp.c | 25 +++++++++++++------------ lib/timeval.c | 8 ++++---- lib/transfer.c | 4 ++-- lib/url.c | 2 +- lib/urlapi.c | 16 ++++++++-------- lib/ws.c | 14 +++++++------- 52 files changed, 258 insertions(+), 240 deletions(-) diff --git a/lib/altsvc.c b/lib/altsvc.c index b72a59612a0bd9..2b017b20072000 100644 --- a/lib/altsvc.c +++ b/lib/altsvc.c @@ -270,7 +270,7 @@ static CURLcode altsvc_out(struct altsvc *as, FILE *fp) "%s %s%s%s %u " "\"%d%02d%02d " "%02d:%02d:%02d\" " - "%u %d\n", + "%u %u\n", Curl_alpnid2str(as->src.alpnid), src6_pre, as->src.host, src6_post, as->src.port, @@ -409,7 +409,7 @@ static CURLcode getalnum(const char **ptr, char *alpnbuf, size_t buflen) protop = p; while(*p && !ISBLANK(*p) && (*p != ';') && (*p != '=')) p++; - len = p - protop; + len = (size_t)(p - protop); *ptr = p; if(!len || (len >= buflen)) @@ -462,7 +462,7 @@ static time_t altsvc_debugtime(void *unused) char *timestr = getenv("CURL_TIME"); (void)unused; if(timestr) { - unsigned long val = strtol(timestr, NULL, 10); + long val = strtol(timestr, NULL, 10); return (time_t)val; } return time(NULL); @@ -546,7 +546,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data, else { while(*p && (ISALNUM(*p) || (*p == '.') || (*p == '-'))) p++; - len = p - hostp; + len = (size_t)(p - hostp); } if(!len || (len >= MAX_ALTSVC_HOSTLEN)) { infof(data, "Excessive alt-svc host name, ignoring."); @@ -624,7 +624,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data, num = strtoul(value_ptr, &end_ptr, 10); if((end_ptr != value_ptr) && (num < ULONG_MAX)) { if(strcasecompare("ma", option)) - maxage = num; + maxage = (time_t)num; else if(strcasecompare("persist", option) && (num == 1)) persist = TRUE; } @@ -696,7 +696,7 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi, if((as->src.alpnid == srcalpnid) && hostcompare(srchost, as->src.host) && (as->src.port == srcport) && - (versions & as->dst.alpnid)) { + (versions & (int)as->dst.alpnid)) { /* match */ *dstentry = as; return TRUE; diff --git a/lib/altsvc.h b/lib/altsvc.h index 7fea1434a543ae..58f1905da61e4a 100644 --- a/lib/altsvc.h +++ b/lib/altsvc.h @@ -47,7 +47,7 @@ struct altsvc { struct althost dst; time_t expires; bool persist; - int prio; + unsigned int prio; struct Curl_llist_element node; }; diff --git a/lib/bufq.c b/lib/bufq.c index c3245516c9fce0..7fc0185dd3d5b1 100644 --- a/lib/bufq.c +++ b/lib/bufq.c @@ -109,7 +109,7 @@ static ssize_t chunk_slurpn(struct buf_chunk *chunk, size_t max_len, nread = reader(reader_ctx, p, n, err); if(nread > 0) { DEBUGASSERT((size_t)nread <= n); - chunk->w_offset += nread; + chunk->w_offset += (size_t)nread; } return nread; } @@ -405,7 +405,7 @@ ssize_t Curl_bufq_write(struct bufq *q, n = chunk_append(tail, buf, len); if(!n) break; - nwritten += n; + nwritten += (ssize_t)n; buf += n; len -= n; } @@ -438,7 +438,7 @@ ssize_t Curl_bufq_read(struct bufq *q, unsigned char *buf, size_t len, while(len && q->head) { n = chunk_read(q->head, buf, len); if(n) { - nread += n; + nread += (ssize_t)n; buf += n; len -= n; } @@ -582,7 +582,7 @@ ssize_t Curl_bufq_write_pass(struct bufq *q, /* Maybe only part of `data` has been added, continue to loop */ buf += (size_t)n; len -= (size_t)n; - nwritten += (size_t)n; + nwritten += n; } if(!nwritten && len) { @@ -656,7 +656,7 @@ static ssize_t bufq_slurpn(struct bufq *q, size_t max_len, *err = CURLE_OK; break; } - nread += (size_t)n; + nread += n; if(max_len) { DEBUGASSERT((size_t)n <= max_len); max_len -= (size_t)n; diff --git a/lib/cf-https-connect.c b/lib/cf-https-connect.c index b23fa056f8faa3..f9994794ca796b 100644 --- a/lib/cf-https-connect.c +++ b/lib/cf-https-connect.c @@ -147,8 +147,10 @@ static void cf_hc_reset(struct Curl_cfilter *cf, struct Curl_easy *data) cf_hc_baller_reset(&ctx->h21_baller, data); ctx->state = CF_HC_INIT; ctx->result = CURLE_OK; - ctx->hard_eyeballs_timeout_ms = data->set.happy_eyeballs_timeout; - ctx->soft_eyeballs_timeout_ms = data->set.happy_eyeballs_timeout / 2; + ctx->hard_eyeballs_timeout_ms = + (int)data->set.happy_eyeballs_timeout; + ctx->soft_eyeballs_timeout_ms = + (int)(data->set.happy_eyeballs_timeout / 2); } } diff --git a/lib/cf-socket.c b/lib/cf-socket.c index eeae5f9950c542..1373162ad2f239 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -1299,7 +1299,7 @@ static ssize_t cf_socket_send(struct Curl_cfilter *cf, struct Curl_easy *data, } } if(cf->cft != &Curl_cft_udp && ctx->wpartial_percent > 0 && len > 8) { - len = len * ctx->wpartial_percent / 100; + len = len * (size_t)ctx->wpartial_percent / 100; if(!len) len = 1; CURL_TRC_CF(data, cf, "send(len=%zu) SIMULATE partial write of %zu bytes", diff --git a/lib/cfilters.c b/lib/cfilters.c index a327fa1944e379..bf46aae033127b 100644 --- a/lib/cfilters.c +++ b/lib/cfilters.c @@ -701,7 +701,7 @@ CURLcode Curl_conn_recv(struct Curl_easy *data, int sockindex, nread = data->conn->recv[sockindex](data, sockindex, buf, blen, &result); DEBUGASSERT(nread >= 0 || result); DEBUGASSERT(nread < 0 || !result); - *n = (nread >= 0)? (size_t)nread : 0; + *n = (nread >= 0)? nread : 0; return result; } diff --git a/lib/content_encoding.c b/lib/content_encoding.c index 13b21dfa50785d..2be6d6620597be 100644 --- a/lib/content_encoding.c +++ b/lib/content_encoding.c @@ -491,10 +491,11 @@ static CURLcode gzip_do_write(struct Curl_easy *data, /* Initial call state */ ssize_t hlen; - switch(check_gzip_header((unsigned char *) buf, nbytes, &hlen)) { + /* FIXME: nbytes cast */ + switch(check_gzip_header((unsigned char *) buf, (ssize_t)nbytes, &hlen)) { case GZIP_OK: z->next_in = (Bytef *) buf + hlen; - z->avail_in = (uInt) (nbytes - hlen); + z->avail_in = (uInt) (nbytes - (size_t)hlen); zp->zlib_init = ZLIB_GZIP_INFLATING; /* Inflating stream state */ break; @@ -987,7 +988,7 @@ CURLcode Curl_build_unencoding_stack(struct Curl_easy *data, for(namelen = 0; *enclist && *enclist != ','; enclist++) if(!ISSPACE(*enclist)) - namelen = enclist - name + 1; + namelen = (size_t)(enclist - name + 1); if(namelen) { const struct Curl_cwtype *cwt; diff --git a/lib/cookie.c b/lib/cookie.c index 837caaab384466..e585238ac7be5d 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -236,9 +236,9 @@ static const char *get_top_domain(const char * const domain, size_t *outlen) len = strlen(domain); last = memrchr(domain, '.', len); if(last) { - first = memrchr(domain, '.', (last - domain)); + first = memrchr(domain, '.', (size_t)(last - domain)); if(first) - len -= (++first - domain); + len -= (size_t)(++first - domain); } } @@ -263,7 +263,7 @@ static size_t cookie_hash_domain(const char *domain, const size_t len) while(domain < end) { h += h << 5; - h ^= Curl_raw_toupper(*domain++); + h ^= (size_t)Curl_raw_toupper(*domain++); } return (h % COOKIE_HASH_SIZE); @@ -820,9 +820,9 @@ Curl_cookie_add(struct Curl_easy *data, if(!queryp) endslash = strrchr(path, '/'); else - endslash = memrchr(path, '/', (queryp - path)); + endslash = memrchr(path, '/', (size_t)(queryp - path)); if(endslash) { - size_t pathlen = (endslash-path + 1); /* include end slash */ + size_t pathlen = (size_t)(endslash-path + 1); /* include end slash */ co->path = Curl_memdup0(path, pathlen); if(co->path) { co->spath = sanitize_cookie_path(co->path); @@ -1087,7 +1087,7 @@ Curl_cookie_add(struct Curl_easy *data, sep = strchr(clist->spath + 1, '/'); if(sep) - cllen = sep - clist->spath; + cllen = (size_t)(sep - clist->spath); else cllen = strlen(clist->spath); @@ -1646,7 +1646,7 @@ static CURLcode cookie_output(struct Curl_easy *data, size_t nvalid = 0; struct Cookie **array; - array = calloc(1, sizeof(struct Cookie *) * c->numcookies); + array = calloc(1, sizeof(struct Cookie *) * (size_t)c->numcookies); if(!array) { error = CURLE_OUT_OF_MEMORY; goto error; diff --git a/lib/curl_ntlm_core.c b/lib/curl_ntlm_core.c index 6f6d75c0318252..79e01ee607f655 100644 --- a/lib/curl_ntlm_core.c +++ b/lib/curl_ntlm_core.c @@ -137,14 +137,14 @@ */ static void extend_key_56_to_64(const unsigned char *key_56, char *key) { - key[0] = key_56[0]; - key[1] = (unsigned char)(((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1)); - key[2] = (unsigned char)(((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2)); - key[3] = (unsigned char)(((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3)); - key[4] = (unsigned char)(((key_56[3] << 4) & 0xFF) | (key_56[4] >> 4)); - key[5] = (unsigned char)(((key_56[4] << 3) & 0xFF) | (key_56[5] >> 5)); - key[6] = (unsigned char)(((key_56[5] << 2) & 0xFF) | (key_56[6] >> 6)); - key[7] = (unsigned char) ((key_56[6] << 1) & 0xFF); + key[0] = (char)key_56[0]; + key[1] = (char)(((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1)); + key[2] = (char)(((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2)); + key[3] = (char)(((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3)); + key[4] = (char)(((key_56[3] << 4) & 0xFF) | (key_56[4] >> 4)); + key[5] = (char)(((key_56[4] << 3) & 0xFF) | (key_56[5] >> 5)); + key[6] = (char)(((key_56[5] << 2) & 0xFF) | (key_56[6] >> 6)); + key[7] = (char) ((key_56[6] << 1) & 0xFF); } #endif diff --git a/lib/curl_trc.c b/lib/curl_trc.c index 54bdd80000fa2c..22062228df0487 100644 --- a/lib/curl_trc.c +++ b/lib/curl_trc.c @@ -101,7 +101,7 @@ void Curl_failf(struct Curl_easy *data, const char *fmt, ...) } error[len++] = '\n'; error[len] = '\0'; - Curl_debug(data, CURLINFO_TEXT, error, len); + Curl_debug(data, CURLINFO_TEXT, error, (size_t)len); va_end(ap); } } @@ -121,10 +121,10 @@ static void trc_infof(struct Curl_easy *data, struct curl_trc_feat *feat, char buffer[MAXINFO + 2]; if(feat) len = msnprintf(buffer, MAXINFO, "[%s] ", feat->name); - len += mvsnprintf(buffer + len, MAXINFO - len, fmt, ap); + len += mvsnprintf(buffer + len, (size_t)(MAXINFO - len), fmt, ap); buffer[len++] = '\n'; buffer[len] = '\0'; - Curl_debug(data, CURLINFO_TEXT, buffer, len); + Curl_debug(data, CURLINFO_TEXT, buffer, (size_t)len); } void Curl_infof(struct Curl_easy *data, const char *fmt, ...) @@ -147,19 +147,20 @@ void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf, int len = 0; char buffer[MAXINFO + 2]; if(data->state.feat) - len += msnprintf(buffer + len, MAXINFO - len, "[%s] ", + len += msnprintf(buffer + len, (size_t)(MAXINFO - len), "[%s] ", data->state.feat->name); if(cf->sockindex) - len += msnprintf(buffer + len, MAXINFO - len, "[%s-%d] ", + len += msnprintf(buffer + len, (size_t)(MAXINFO - len), "[%s-%d] ", cf->cft->name, cf->sockindex); else - len += msnprintf(buffer + len, MAXINFO - len, "[%s] ", cf->cft->name); + len += msnprintf(buffer + len, (size_t)(MAXINFO - len), "[%s] ", + cf->cft->name); va_start(ap, fmt); - len += mvsnprintf(buffer + len, MAXINFO - len, fmt, ap); + len += mvsnprintf(buffer + len, (size_t)(MAXINFO - len), fmt, ap); va_end(ap); buffer[len++] = '\n'; buffer[len] = '\0'; - Curl_debug(data, CURLINFO_TEXT, buffer, len); + Curl_debug(data, CURLINFO_TEXT, buffer, (size_t)len); } } diff --git a/lib/doh.c b/lib/doh.c index f3c69ca4bb8490..e2960b2762fadd 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -144,7 +144,7 @@ UNITTEST DOHcode doh_encode(const char *host, size_t labellen; char *dot = strchr(hostp, '.'); if(dot) - labellen = dot - hostp; + labellen = (size_t)(dot - hostp); else labellen = strlen(hostp); if((labellen > 63) || (!labellen)) { @@ -171,7 +171,7 @@ UNITTEST DOHcode doh_encode(const char *host, *dnsp++ = '\0'; /* upper 8 bit CLASS */ *dnsp++ = DNS_CLASS_IN; /* IN - "the Internet" */ - *olen = dnsp - orig; + *olen = (size_t)(dnsp - orig); /* verify that our estimation of length is valid, since * this has led to buffer overflows in this function */ @@ -518,12 +518,12 @@ static DOHcode skipqname(const unsigned char *doh, size_t dohlen, return DOH_OK; } -static unsigned short get16bit(const unsigned char *doh, int index) +static unsigned short get16bit(const unsigned char *doh, unsigned int index) { return (unsigned short)((doh[index] << 8) | doh[index + 1]); } -static unsigned int get32bit(const unsigned char *doh, int index) +static unsigned int get32bit(const unsigned char *doh, unsigned int index) { /* make clang and gcc optimize this to bswap by incrementing the pointer first. */ @@ -606,7 +606,7 @@ static DOHcode store_cname(const unsigned char *doh, /* move to the new index */ newpos = (length & 0x3f) << 8 | doh[index + 1]; - index = newpos; + index = (unsigned int)newpos; continue; } else if(length & 0xc0) @@ -670,7 +670,7 @@ static DOHcode rdata(const unsigned char *doh, break; #endif case DNS_TYPE_CNAME: - rc = store_cname(doh, dohlen, index, d); + rc = store_cname(doh, dohlen, (unsigned int)index, d); if(rc) return rc; break; @@ -771,7 +771,7 @@ UNITTEST DOHcode doh_decode(const unsigned char *doh, if(dohlen < (index + rdlength)) return DOH_DNS_OUT_OF_RANGE; - rc = rdata(doh, dohlen, rdlength, type, index, d); + rc = rdata(doh, dohlen, rdlength, type, (int)index, d); if(rc) return rc; /* bad rdata */ index += rdlength; @@ -854,7 +854,7 @@ static void showdoh(struct Curl_easy *data, char buffer[128]; char *ptr; size_t len; - len = msnprintf(buffer, 128, "[DoH] AAAA: "); + len = (size_t)msnprintf(buffer, 128, "[DoH] AAAA: "); ptr = &buffer[len]; len = sizeof(buffer) - len; for(j = 0; j < 16; j += 2) { diff --git a/lib/dynhds.c b/lib/dynhds.c index d7548959b2ed9f..8c259512639480 100644 --- a/lib/dynhds.c +++ b/lib/dynhds.c @@ -251,7 +251,7 @@ CURLcode Curl_dynhds_h1_add_line(struct dynhds *dynhds, if(!p) return CURLE_BAD_FUNCTION_ARGUMENT; name = line; - namelen = p - line; + namelen = (size_t)(p - line); p++; /* move past the colon */ for(i = namelen + 1; i < line_len; ++i, ++p) { if(!ISBLANK(*p)) diff --git a/lib/easy.c b/lib/easy.c index f4f4d2cc634e92..ef2252c7a15c99 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -579,7 +579,7 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev) before = Curl_now(); /* wait for activity or timeout */ - pollrc = Curl_poll(fds, numfds, ev->ms); + pollrc = Curl_poll(fds, (unsigned int)numfds, ev->ms); if(pollrc < 0) return CURLE_UNRECOVERABLE_POLL; diff --git a/lib/escape.c b/lib/escape.c index 5af00c3514fd24..16b124265e0cce 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -70,7 +70,8 @@ char *curl_easy_escape(struct Curl_easy *data, const char *string, return strdup(""); while(length--) { - unsigned char in = *string++; /* treat the characters unsigned */ + /* treat the characters unsigned */ + unsigned char in = (unsigned char)*string++; if(ISUNRESERVED(in)) { /* append this */ @@ -137,7 +138,7 @@ CURLcode Curl_urldecode(const char *string, size_t length, *ostring = ns; while(alloc) { - unsigned char in = *string; + unsigned char in = (unsigned char)*string; if(('%' == in) && (alloc > 2) && ISXDIGIT(string[1]) && ISXDIGIT(string[2])) { /* this is two hexadecimal digits following a '%' */ @@ -157,13 +158,13 @@ CURLcode Curl_urldecode(const char *string, size_t length, return CURLE_URL_MALFORMAT; } - *ns++ = in; + *ns++ = (char)in; } *ns = 0; /* terminate it */ if(olen) /* store output size */ - *olen = ns - *ostring; + *olen = (size_t)(ns - *ostring); return CURLE_OK; } @@ -222,8 +223,8 @@ void Curl_hexencode(const unsigned char *src, size_t len, /* input length */ while(len-- && (olen >= 3)) { /* clang-tidy warns on this line without this comment: */ /* NOLINTNEXTLINE(clang-analyzer-core.UndefinedBinaryOperatorResult) */ - *out++ = hex[(*src & 0xF0)>>4]; - *out++ = hex[*src & 0x0F]; + *out++ = (unsigned char)hex[(*src & 0xF0)>>4]; + *out++ = (unsigned char)hex[*src & 0x0F]; ++src; olen -= 2; } diff --git a/lib/file.c b/lib/file.c index cae1cee59c99a0..69db56d7aceaa0 100644 --- a/lib/file.c +++ b/lib/file.c @@ -370,7 +370,7 @@ static CURLcode file_upload(struct Curl_easy *data) /* skip bytes before resume point */ if(data->state.resume_from) { if((curl_off_t)nread <= data->state.resume_from) { - data->state.resume_from -= nread; + data->state.resume_from -= (curl_off_t)nread; nread = 0; sendbuf = xfer_ulbuf; } @@ -390,7 +390,7 @@ static CURLcode file_upload(struct Curl_easy *data) break; } - bytecount += nread; + bytecount += (curl_off_t)nread; Curl_pgrsSetUploadCounter(data, bytecount); @@ -470,7 +470,8 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) headerlen = msnprintf(header, sizeof(header), "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", expected_size); - result = Curl_client_write(data, CLIENTWRITE_HEADER, header, headerlen); + result = Curl_client_write(data, CLIENTWRITE_HEADER, + header, (size_t)headerlen); if(result) return result; @@ -496,7 +497,8 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) tm->tm_min, tm->tm_sec, data->req.no_body ? "": "\r\n"); - result = Curl_client_write(data, CLIENTWRITE_HEADER, header, headerlen); + result = Curl_client_write(data, CLIENTWRITE_HEADER, + header, (size_t)headerlen); if(result) return result; /* set the file size to make it available post transfer */ @@ -587,7 +589,8 @@ static CURLcode file_do(struct Curl_easy *data, bool *done) if(size_known) expected_size -= nread; - result = Curl_client_write(data, CLIENTWRITE_BODY, xfer_buf, nread); + result = Curl_client_write(data, CLIENTWRITE_BODY, + xfer_buf, (size_t)nread); if(result) goto out; diff --git a/lib/formdata.c b/lib/formdata.c index d6a1697aa73a31..f756a7240a741e 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -318,7 +318,8 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, break; case CURLFORM_CONTENTSLENGTH: current_form->contentslength = - array_state?(size_t)array_value:(size_t)va_arg(params, long); + array_state?(curl_off_t)(size_t)array_value: + (curl_off_t)(size_t)va_arg(params, long); break; case CURLFORM_CONTENTLEN: @@ -842,7 +843,7 @@ CURLcode Curl_getformdata(struct Curl_easy *data, if(!part) result = CURLE_OUT_OF_MEMORY; if(!result) - result = setname(part, post->name, post->namelength); + result = setname(part, post->name, (size_t)post->namelength); if(!result) { multipart = curl_mime_init(data); if(!multipart) @@ -869,7 +870,7 @@ CURLcode Curl_getformdata(struct Curl_easy *data, /* Set field name. */ if(!result && !post->more) - result = setname(part, post->name, post->namelength); + result = setname(part, post->name, (size_t)post->namelength); /* Process contents. */ if(!result) { @@ -895,8 +896,8 @@ CURLcode Curl_getformdata(struct Curl_easy *data, result = curl_mime_filename(part, NULL); } else if(post->flags & HTTPPOST_BUFFER) - result = curl_mime_data(part, post->buffer, - post->bufferlength? post->bufferlength: -1); + result = curl_mime_data(part, post->buffer, (size_t) + (post->bufferlength? post->bufferlength: -1)); else if(post->flags & HTTPPOST_CALLBACK) { /* the contents should be read with the callback and the size is set with the contentslength */ diff --git a/lib/ftp.c b/lib/ftp.c index 9e10704f2c9aae..a0bc64847426f7 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -308,7 +308,7 @@ static CURLcode ftp_cw_lc_write(struct Curl_easy *data, break; /* write the bytes before the '\r', excluding the '\r' */ - chunk_len = cp - buf; + chunk_len = (size_t)(cp - buf); if(chunk_len) { result = Curl_cwriter_write(data, writer->next, chunk_type, buf, chunk_len); @@ -822,7 +822,7 @@ CURLcode Curl_GetFTPResponse(struct Curl_easy *data, counter */ cache_skip = 0; - *nreadp += nread; + *nreadp += (ssize_t)nread; } /* while there's buffer left and loop is requested */ @@ -1064,7 +1064,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, char *ip_start = string_ftpport + 1; ip_end = strchr(ip_start, ']'); if(ip_end) { - addrlen = ip_end - ip_start; + addrlen = (size_t)(ip_end - ip_start); addr = ip_start; } } @@ -1079,7 +1079,7 @@ static CURLcode ftp_state_use_port(struct Curl_easy *data, addr = string_ftpport; if(ip_end) { /* either ipv6 or (ipv4|domain|interface):port(-range) */ - addrlen = ip_end - string_ftpport; + addrlen = (size_t)(ip_end - string_ftpport); #ifdef USE_IPV6 if(Curl_inet_pton(AF_INET6, string_ftpport, &sa6->sin6_addr) == 1) { /* ipv6 */ @@ -1550,7 +1550,7 @@ static CURLcode ftp_state_list(struct Curl_easy *data) if(slashPos) { /* chop off the file part if format is dir/file otherwise remove the trailing slash for dir/dir/ except for absolute path / */ - size_t n = slashPos - rawPath; + size_t n = (size_t)(slashPos - rawPath); if(n == 0) ++n; @@ -1712,7 +1712,7 @@ static CURLcode ftp_state_ul_setup(struct Curl_easy *data, data->state.fread_func(scratch, 1, readthisamountnow, data->state.in); - passed += actuallyread; + passed += (curl_off_t)actuallyread; if((actuallyread == 0) || (actuallyread > readthisamountnow)) { /* this checks for greater-than only to make sure that the CURL_READFUNC_ABORT return code still aborts */ @@ -2262,7 +2262,7 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data, tm->tm_hour, tm->tm_min, tm->tm_sec); - result = client_write_header(data, headerbuf, headerbuflen); + result = client_write_header(data, headerbuf, (size_t)headerbuflen); if(result) return result; } /* end of a ridiculous amount of conditionals */ @@ -2473,7 +2473,7 @@ static CURLcode ftp_state_size_resp(struct Curl_easy *data, char clbuf[128]; int clbuflen = msnprintf(clbuf, sizeof(clbuf), "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", filesize); - result = client_write_header(data, clbuf, clbuflen); + result = client_write_header(data, clbuf, (size_t)clbuflen); if(result) return result; } @@ -3085,7 +3085,7 @@ static CURLcode ftp_statemachine(struct Curl_easy *data, ptr++; for(start = ptr; *ptr && *ptr != ' '; ptr++) ; - os = Curl_memdup0(start, ptr - start); + os = Curl_memdup0(start, (size_t)(ptr - start)); if(!os) return CURLE_OUT_OF_MEMORY; @@ -4292,7 +4292,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data) slashPos = strrchr(rawPath, '/'); if(slashPos) { /* get path before last slash, except for / */ - size_t dirlen = slashPos - rawPath; + size_t dirlen = (size_t)(slashPos - rawPath); if(dirlen == 0) dirlen = 1; @@ -4336,7 +4336,7 @@ CURLcode ftp_parse_url_path(struct Curl_easy *data) /* parse the URL path into separate path components */ while((slashPos = strchr(curPos, '/'))) { - size_t compLen = slashPos - curPos; + size_t compLen = (size_t)(slashPos - curPos); /* path starts with a slash: add that as a directory */ if((compLen == 0) && (ftpc->dirdepth == 0)) diff --git a/lib/getinfo.c b/lib/getinfo.c index e423f0b29a993e..14941bf4c68ce7 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -204,7 +204,7 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info, #ifdef DEBUGBUILD char *timestr = getenv("CURL_TIME"); if(timestr) { - unsigned long val = strtol(timestr, NULL, 10); + unsigned long val = (unsigned long)strtol(timestr, NULL, 10); switch(info) { case CURLINFO_LOCAL_PORT: *param_longp = (long)val; @@ -216,7 +216,7 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info, /* use another variable for this to allow different values */ timestr = getenv("CURL_DEBUG_SIZE"); if(timestr) { - unsigned long val = strtol(timestr, NULL, 10); + unsigned long val = (unsigned long)strtol(timestr, NULL, 10); switch(info) { case CURLINFO_HEADER_SIZE: case CURLINFO_REQUEST_SIZE: @@ -361,7 +361,7 @@ static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info, #ifdef DEBUGBUILD char *timestr = getenv("CURL_TIME"); if(timestr) { - unsigned long val = strtol(timestr, NULL, 10); + unsigned long val = (unsigned long)strtol(timestr, NULL, 10); switch(info) { case CURLINFO_TOTAL_TIME_T: case CURLINFO_NAMELOOKUP_TIME_T: @@ -450,7 +450,7 @@ static CURLcode getinfo_double(struct Curl_easy *data, CURLINFO info, #ifdef DEBUGBUILD char *timestr = getenv("CURL_TIME"); if(timestr) { - unsigned long val = strtol(timestr, NULL, 10); + unsigned long val = (unsigned long)strtol(timestr, NULL, 10); switch(info) { case CURLINFO_TOTAL_TIME: case CURLINFO_NAMELOOKUP_TIME: diff --git a/lib/gopher.c b/lib/gopher.c index 7ba070a769b344..a2344cfb83c4db 100644 --- a/lib/gopher.c +++ b/lib/gopher.c @@ -187,14 +187,14 @@ static CURLcode gopher_do(struct Curl_easy *data, bool *done) if(strlen(sel) < 1) break; - result = Curl_xfer_send(data, sel, k, &amount); + result = Curl_xfer_send(data, sel, (size_t)k, &amount); if(!result) { /* Which may not have written it all! */ result = Curl_client_write(data, CLIENTWRITE_HEADER, sel, amount); if(result) break; - k -= amount; - sel += amount; + k -= (ssize_t)amount; + sel += (size_t)amount; if(k < 1) break; /* but it did write it all */ } diff --git a/lib/hash.c b/lib/hash.c index 045e8f7243b661..478236750b57a4 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -91,7 +91,7 @@ mk_hash_element(const void *key, size_t key_len, const void *p) return he; } -#define FETCH_LIST(x,y,z) &x->table[x->hash_func(y, z, x->slots)] +#define FETCH_LIST(x,y,z) &x->table[x->hash_func(y, z, (size_t)x->slots)] /* Insert the data in the hash. If there already was a match in the hash, that * data is replaced. This function also "lazily" allocates the table if @@ -109,10 +109,10 @@ Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p) struct Curl_llist *l; DEBUGASSERT(h); - DEBUGASSERT(h->slots); + DEBUGASSERT(h->slots > 0); if(!h->table) { int i; - h->table = malloc(h->slots * sizeof(struct Curl_llist)); + h->table = malloc((size_t)h->slots * sizeof(struct Curl_llist)); if(!h->table) return NULL; /* OOM */ for(i = 0; i < h->slots; ++i) @@ -279,7 +279,7 @@ size_t Curl_hash_str(void *key, size_t key_length, size_t slots_num) while(key_str < end) { h += h << 5; - h ^= *key_str++; + h ^= (size_t)*key_str++; } return (h % slots_num); @@ -370,7 +370,7 @@ void Curl_hash_print(struct Curl_hash *h, #endif void Curl_hash_offt_init(struct Curl_hash *h, - unsigned int slots, + int slots, Curl_hash_dtor dtor) { Curl_hash_init(h, slots, Curl_hash_str, Curl_str_key_compare, dtor); diff --git a/lib/hash.h b/lib/hash.h index 7ffced50bcd772..5316e408161dec 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -100,7 +100,7 @@ void Curl_hash_print(struct Curl_hash *h, /* Hash for `curl_off_t` as key */ void Curl_hash_offt_init(struct Curl_hash *h, - unsigned int slots, + int slots, Curl_hash_dtor dtor); void *Curl_hash_offt_set(struct Curl_hash *h, curl_off_t id, void *elem); diff --git a/lib/headers.c b/lib/headers.c index ef947492de4abf..f1b79e9a8c45b4 100644 --- a/lib/headers.c +++ b/lib/headers.c @@ -231,7 +231,7 @@ static CURLcode unfold_value(struct Curl_easy *data, const char *value, DEBUGASSERT(data->state.prevhead); hs = data->state.prevhead; olen = strlen(hs->value); - offset = hs->value - hs->buffer; + offset = (size_t)(hs->value - hs->buffer); oalloc = olen + offset + 1; /* skip all trailing space letters */ @@ -295,7 +295,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header, /* neither CR nor LF as terminator is not a valid header */ return CURLE_WEIRD_SERVER_REPLY; } - hlen = end - header; + hlen = (size_t)(end - header); if((header[0] == ' ') || (header[0] == '\t')) { if(data->state.prevhead) diff --git a/lib/hostip.c b/lib/hostip.c index 801de5ce43bc11..4238022eaa397d 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -176,7 +176,7 @@ create_hostcache_id(const char *name, *ptr++ = Curl_raw_tolower(*name++); olen++; } - olen += msnprintf(ptr, 7, ":%u", port); + olen += (size_t)msnprintf(ptr, 7, ":%u", port); return olen; } @@ -415,11 +415,11 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, struct Curl_addrinfo **nodes; infof(data, "Shuffling %i addresses", num_addrs); - nodes = malloc(num_addrs*sizeof(*nodes)); + nodes = malloc((size_t)num_addrs * sizeof(*nodes)); if(nodes) { int i; unsigned int *rnd; - const size_t rnd_size = num_addrs * sizeof(*rnd); + const size_t rnd_size = (size_t)num_addrs * sizeof(*rnd); /* build a plain array of Curl_addrinfo pointers */ nodes[0] = *addr; @@ -433,8 +433,8 @@ UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data, if(Curl_rand(data, (unsigned char *)rnd, rnd_size) == CURLE_OK) { struct Curl_addrinfo *swap_tmp; for(i = num_addrs - 1; i > 0; i--) { - swap_tmp = nodes[rnd[i] % (i + 1)]; - nodes[rnd[i] % (i + 1)] = nodes[i]; + swap_tmp = nodes[rnd[i] % (unsigned int)(i + 1)]; + nodes[rnd[i] % (unsigned int)(i + 1)] = nodes[i]; nodes[i] = swap_tmp; } @@ -1139,7 +1139,7 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) host_end = strchr(&hostp->data[1], ':'); if(host_end) { - hlen = host_end - &hostp->data[1]; + hlen = (size_t)(host_end - &hostp->data[1]); num = strtoul(++host_end, NULL, 10); if(!hlen || (num > 0xffff)) host_end = NULL; @@ -1187,7 +1187,7 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) host_end = strchr(host_begin, ':'); if(!host_end) goto err; - hlen = host_end - host_begin; + hlen = (size_t)(host_end - host_begin); port_ptr = host_end + 1; tmp_port = strtoul(port_ptr, &end_ptr, 10); @@ -1217,7 +1217,7 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data) --addr_end; } - alen = addr_end - addr_begin; + alen = (size_t)(addr_end - addr_begin); if(!alen) continue; diff --git a/lib/http.c b/lib/http.c index 92d991c1a7c3fe..3f2be098d21139 100644 --- a/lib/http.c +++ b/lib/http.c @@ -258,7 +258,7 @@ char *Curl_copy_header_value(const char *header) end--; /* get length of the type */ - len = end - start + 1; + len = (size_t)(end - start) + 1; return Curl_memdup0(start, len); } @@ -1126,7 +1126,8 @@ Curl_compareheader(const char *headerline, /* line to check */ end = strchr(start, '\0'); } - len = end-start; /* length of the content part of the input line */ + /* length of the content part of the input line */ + len = (size_t)(end - start); /* find the content string in the rest of the line */ for(; len >= clen; len--, start++) { @@ -1316,7 +1317,7 @@ CURLcode Curl_dynhds_add_custom(struct Curl_easy *data, ptr = strchr(headers->data, ':'); if(ptr) { name = headers->data; - namelen = ptr - headers->data; + namelen = (size_t)(ptr - headers->data); ptr++; /* pass the colon */ while(*ptr && ISSPACE(*ptr)) ptr++; @@ -1339,7 +1340,7 @@ CURLcode Curl_dynhds_add_custom(struct Curl_easy *data, } name = headers->data; - namelen = ptr - headers->data; + namelen = (size_t)(ptr - headers->data); ptr++; /* pass the semicolon */ while(*ptr && ISSPACE(*ptr)) ptr++; @@ -3870,7 +3871,7 @@ static CURLcode http_parse_headers(struct Curl_easy *data, } /* decrease the size of the remaining (supposed) header line */ - consumed = (end_ptr - buf) + 1; + consumed = (size_t)(end_ptr - buf) + 1; result = Curl_dyn_addn(&data->state.headerb, buf, consumed); if(result) return result; diff --git a/lib/http1.c b/lib/http1.c index 182234ca977fe5..32e3b8f6453689 100644 --- a/lib/http1.c +++ b/lib/http1.c @@ -94,7 +94,7 @@ static ssize_t detect_line(struct h1_req_parser *parser, return -1; } parser->line = buf; - parser->line_len = line_end - buf + 1; + parser->line_len = (size_t)(line_end - buf) + 1; *err = CURLE_OK; return (ssize_t)parser->line_len; } @@ -149,7 +149,7 @@ static CURLcode start_req(struct h1_req_parser *parser, goto out; m = parser->line; - m_len = p - parser->line; + m_len = (size_t)(p - parser->line); target = p + 1; target_len = hv_len = 0; hv = NULL; @@ -159,7 +159,7 @@ static CURLcode start_req(struct h1_req_parser *parser, if(parser->line[i] == ' ') { hv = &parser->line[i + 1]; hv_len = parser->line_len - i; - target_len = (hv - target) - 1; + target_len = (size_t)(hv - target) - 1; break; } } @@ -217,7 +217,7 @@ static CURLcode start_req(struct h1_req_parser *parser, tmp[target_len] = '\0'; /* See if treating TARGET as an absolute URL makes sense */ if(Curl_is_absolute_url(tmp, NULL, 0, FALSE)) { - int url_options; + unsigned int url_options; url = curl_url(); if(!url) { @@ -277,7 +277,7 @@ ssize_t Curl_h1_req_parse_read(struct h1_req_parser *parser, } /* Consume this line */ - nread += (size_t)n; + nread += (ssize_t)n; buf += (size_t)n; buflen -= (size_t)n; diff --git a/lib/http_aws_sigv4.c b/lib/http_aws_sigv4.c index 98cc033a083463..940363bad5d65a 100644 --- a/lib/http_aws_sigv4.c +++ b/lib/http_aws_sigv4.c @@ -325,7 +325,8 @@ static char *parse_content_sha_hdr(struct Curl_easy *data, char *value; size_t len; - key_len = msnprintf(key, sizeof(key), "x-%s-content-sha256", provider1); + key_len = (size_t)msnprintf(key, sizeof(key), "x-%s-content-sha256", + provider1); value = Curl_checkheaders(data, key, key_len); if(!value) @@ -442,7 +443,7 @@ static CURLcode canon_query(struct Curl_easy *data, ap->p = p; amp = strchr(p, '&'); if(amp) - ap->len = amp - p; /* excluding the ampersand */ + ap->len = (size_t)(amp - p); /* excluding the ampersand */ else { ap->len = strlen(p); break; @@ -456,7 +457,7 @@ static CURLcode canon_query(struct Curl_easy *data, return CURLE_URL_MALFORMAT; } - qsort(&array[0], entry, sizeof(struct pair), compare_func); + qsort(&array[0], (size_t)entry, sizeof(struct pair), compare_func); ap = &array[0]; for(i = 0; !result && (i < entry); i++, ap++) { @@ -605,7 +606,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data, bool proxy) result = CURLE_URL_MALFORMAT; goto fail; } - len = hostdot - hostname; + len = (size_t)(hostdot - hostname); if(len > MAX_SIGV4_LEN) { failf(data, "aws-sigv4: service too long in hostname"); result = CURLE_URL_MALFORMAT; @@ -624,7 +625,7 @@ CURLcode Curl_output_aws_sigv4(struct Curl_easy *data, bool proxy) result = CURLE_URL_MALFORMAT; goto fail; } - len = hostreg - reg; + len = (size_t)(hostreg - reg); if(len > MAX_SIGV4_LEN) { failf(data, "aws-sigv4: region too long in hostname"); result = CURLE_URL_MALFORMAT; diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 48e7e462bad32a..85d72419d85b90 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -222,7 +222,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data, } *pconsumed += piece; - ch->datasize -= piece; /* decrease amount left to expect */ + ch->datasize -= (curl_off_t)piece; /* decrease amount left to expect */ buf += piece; /* move read pointer forward */ blen -= piece; /* decrease space left in this round */ CURL_TRC_WRITE(data, "http_chunked, write %zu body bytes, %" @@ -345,7 +345,7 @@ static CURLcode httpchunk_readwrite(struct Curl_easy *data, (*pconsumed)++; /* Record the length of any data left in the end of the buffer even if there's no more chunks to read */ - ch->datasize = blen; + ch->datasize = (curl_off_t)blen; ch->state = CHUNK_DONE; CURL_TRC_WRITE(data, "http_chunk, response complete"); return CURLE_OK; @@ -589,7 +589,7 @@ static CURLcode add_chunk(struct Curl_easy *data, if(hdlen <= 0) return CURLE_READ_ERROR; /* On a soft-limited bufq, we do not need to check that all was written */ - result = Curl_bufq_cwrite(&ctx->chunkbuf, hd, hdlen, &n); + result = Curl_bufq_cwrite(&ctx->chunkbuf, hd, (size_t)hdlen, &n); if(!result) result = Curl_bufq_cwrite(&ctx->chunkbuf, buf, nread, &n); if(!result) diff --git a/lib/http_digest.c b/lib/http_digest.c index 2db3125a8e6656..ea720e7cc903aa 100644 --- a/lib/http_digest.c +++ b/lib/http_digest.c @@ -147,7 +147,7 @@ CURLcode Curl_output_digest(struct Curl_easy *data, if(authp->iestyle) { tmp = strchr((char *)uripath, '?'); if(tmp) { - size_t urilen = tmp - (char *)uripath; + size_t urilen = (size_t)(tmp - (char *)uripath); /* typecast is fine here since the value is always less than 32 bits */ path = (unsigned char *) aprintf("%.*s", (int)urilen, uripath); } diff --git a/lib/if2ip.c b/lib/if2ip.c index 36dfe8b396a586..4a2044a80145d2 100644 --- a/lib/if2ip.c +++ b/lib/if2ip.c @@ -162,7 +162,8 @@ if2ip_result_t Curl_if2ip(int af, &((struct sockaddr_in *)(void *)iface->ifa_addr)->sin_addr; res = IF2IP_FOUND; ip = Curl_inet_ntop(af, addr, ipstr, sizeof(ipstr)); - msnprintf(buf, buf_size, "%s%s", ip, scope); + /* FIXME: check if buf_size is not negative */ + msnprintf(buf, (size_t)buf_size, "%s%s", ip, scope); break; } } diff --git a/lib/imap.c b/lib/imap.c index 679bfae977f443..efc9a300e0eb23 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -776,7 +776,7 @@ static CURLcode imap_perform_append(struct Curl_easy *data) /* Prepare the mime data if some. */ if(data->set.mimepost.kind != MIMEKIND_NONE) { /* Use the whole structure as data. */ - data->set.mimepost.flags &= ~MIME_BODY_ONLY; + data->set.mimepost.flags &= ~(unsigned int)MIME_BODY_ONLY; /* Add external headers and mime version. */ curl_mime_headers(&data->set.mimepost, data->set.headers, 0); @@ -1197,7 +1197,7 @@ static CURLcode imap_state_fetch_resp(struct Curl_easy *data, return result; infof(data, "Written %zu bytes, %" CURL_FORMAT_CURL_OFF_TU - " bytes are left for transfer", chunk, size - chunk); + " bytes are left for transfer", chunk, size - (curl_off_t)chunk); /* Have we used the entire overflow or just part of it?*/ if(pp->overflow > chunk) { @@ -1915,7 +1915,7 @@ static CURLcode imap_parse_url_options(struct connectdata *conn) else if(strncasecompare(key, "AUTH=", 5)) { prefer_login = false; result = Curl_sasl_parse_url_auth_option(&imapc->sasl, - value, ptr - value); + value, (size_t)(ptr - value)); } else { prefer_login = false; @@ -1970,7 +1970,7 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data) if(end > begin && end[-1] == '/') end--; - result = Curl_urldecode(begin, end - begin, &imap->mailbox, NULL, + result = Curl_urldecode(begin, (size_t)(end - begin), &imap->mailbox, NULL, REJECT_CTRL); if(result) return result; @@ -1993,7 +1993,7 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data) return CURLE_URL_MALFORMAT; /* Decode the name parameter */ - result = Curl_urldecode(begin, ptr - begin, &name, NULL, + result = Curl_urldecode(begin, (size_t)(ptr - begin), &name, NULL, REJECT_CTRL); if(result) return result; @@ -2004,7 +2004,7 @@ static CURLcode imap_parse_url_path(struct Curl_easy *data) ptr++; /* Decode the value parameter */ - result = Curl_urldecode(begin, ptr - begin, &value, &valuelen, + result = Curl_urldecode(begin, (size_t)(ptr - begin), &value, &valuelen, REJECT_CTRL); if(result) { free(name); diff --git a/lib/mime.c b/lib/mime.c index 5bc6d389314a0a..87d2909eb7123b 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -782,7 +782,7 @@ static size_t readback_bytes(struct mime_state *state, sz = bufsize; memcpy(buffer, bytes, sz); - state->offset += sz; + state->offset += (curl_off_t)sz; return sz; } @@ -843,7 +843,7 @@ static size_t read_part_content(curl_mimepart *part, part->lastreadstatus = sz; break; default: - part->state.offset += sz; + part->state.offset += (curl_off_t)sz; part->lastreadstatus = sz; break; } @@ -1137,7 +1137,7 @@ static void cleanup_part_content(curl_mimepart *part) part->datasize = (curl_off_t) 0; /* No size yet. */ cleanup_encoder_state(&part->encstate); part->kind = MIMEKIND_NONE; - part->flags &= ~MIME_FAST_READ; + part->flags &= ~(unsigned int)MIME_FAST_READ; part->lastreadstatus = 1; /* Successful read status. */ part->state.state = MIMESTATE_BEGIN; } @@ -1388,7 +1388,7 @@ CURLcode curl_mime_data(curl_mimepart *part, if(!part->data) return CURLE_OUT_OF_MEMORY; - part->datasize = datasize; + part->datasize = (curl_off_t)datasize; part->readfunc = mime_mem_read; part->seekfunc = mime_mem_seek; part->freefunc = mime_mem_free; @@ -1498,7 +1498,7 @@ CURLcode curl_mime_headers(curl_mimepart *part, if(part->flags & MIME_USERHEADERS_OWNER) { if(part->userheaders != headers) /* Allow setting twice the same list. */ curl_slist_free_all(part->userheaders); - part->flags &= ~MIME_USERHEADERS_OWNER; + part->flags &= ~(unsigned int)MIME_USERHEADERS_OWNER; } part->userheaders = headers; if(headers && take_ownership) @@ -1662,8 +1662,9 @@ static curl_off_t mime_size(curl_mimepart *part) if(size >= 0 && !(part->flags & MIME_BODY_ONLY)) { /* Compute total part size. */ - size += slist_size(part->curlheaders, 2, NULL, 0); - size += slist_size(part->userheaders, 2, STRCONST("Content-Type")); + size += (curl_off_t)slist_size(part->curlheaders, 2, NULL, 0); + size += (curl_off_t)slist_size(part->userheaders, 2, + STRCONST("Content-Type")); size += 2; /* CRLF after headers. */ } return size; @@ -2006,7 +2007,7 @@ static CURLcode cr_mime_read(struct Curl_easy *data, ctx->error_result = CURLE_READ_ERROR; return CURLE_READ_ERROR; } - ctx->read_len += nread; + ctx->read_len += (curl_off_t)nread; if(ctx->total_len >= 0) ctx->seen_eos = (ctx->read_len >= ctx->total_len); *pnread = nread; diff --git a/lib/mqtt.c b/lib/mqtt.c index 6f150cee4520b1..9aa55f39d12caf 100644 --- a/lib/mqtt.c +++ b/lib/mqtt.c @@ -154,15 +154,15 @@ static int mqtt_getsock(struct Curl_easy *data, static int mqtt_encode_len(char *buf, size_t len) { - unsigned char encoded; int i; for(i = 0; (len > 0) && (i<4); i++) { + unsigned char encoded; encoded = len % 0x80; len /= 0x80; if(len) encoded |= 0x80; - buf[i] = encoded; + buf[i] = (char)encoded; } return i; @@ -173,7 +173,7 @@ static int add_passwd(const char *passwd, const size_t plen, char *pkt, const size_t start, int remain_pos) { /* magic number that need to be set properly */ - const size_t conn_flags_pos = remain_pos + 8; + const size_t conn_flags_pos = (size_t)remain_pos + 8; if(plen > 0xffff) return 1; @@ -192,7 +192,7 @@ static int add_user(const char *username, const size_t ulen, unsigned char *pkt, const size_t start, int remain_pos) { /* magic number that need to be set properly */ - const size_t conn_flags_pos = remain_pos + 8; + const size_t conn_flags_pos = (size_t)remain_pos + 8; if(ulen > 0xffff) return 1; @@ -224,7 +224,7 @@ static int init_connpack(char *packet, char *remain, int remain_pos) /* packet type */ packet[0] = MQTT_MSG_CONNECT; /* remaining length field */ - memcpy(&packet[1], remain, remain_pos); + memcpy(&packet[1], remain, (size_t)remain_pos); /* Fixed header ends */ /* Variable header starts */ @@ -284,7 +284,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) remain_pos = mqtt_encode_len(remain, payloadlen + 10); /* 10 length of variable header and 1 the first byte of the fixed header */ - packetlen = payloadlen + 10 + remain_pos + 1; + packetlen = payloadlen + 10 + (size_t)remain_pos + 1; /* allocating packet */ if(packetlen > 268435455) @@ -300,7 +300,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) result = Curl_rand_alnum(data, (unsigned char *)&client_id[clen], MQTT_CLIENTID_LEN - clen + 1); /* add client id */ - rc = add_client_id(client_id, strlen(client_id), packet, pos + 1); + rc = add_client_id(client_id, strlen(client_id), packet, (size_t)pos + 1); if(rc) { failf(data, "Client ID length mismatched: [%zu]", strlen(client_id)); result = CURLE_WEIRD_SERVER_REPLY; @@ -309,7 +309,7 @@ static CURLcode mqtt_connect(struct Curl_easy *data) infof(data, "Using client id '%s'", client_id); /* position where starts the user payload */ - start_user = pos + 3 + MQTT_CLIENTID_LEN; + start_user = (size_t)pos + 3 + MQTT_CLIENTID_LEN; /* position where starts the password payload */ start_pwd = start_user + ulen; /* if user name was provided, add it to the packet */ @@ -452,7 +452,7 @@ static CURLcode mqtt_subscribe(struct Curl_easy *data) packetlen = topiclen + 5; /* packetid + topic (has a two byte length field) + 2 bytes topic length + QoS byte */ - n = mqtt_encode_len((char *)encodedsize, packetlen); + n = (size_t)mqtt_encode_len((char *)encodedsize, packetlen); packetlen += n + 1; /* add one for the control packet type byte */ packet = malloc(packetlen); @@ -538,7 +538,7 @@ static CURLcode mqtt_publish(struct Curl_easy *data) goto fail; remaininglength = payloadlen + 2 + topiclen; - encodelen = mqtt_encode_len(encodedbytes, remaininglength); + encodelen = (size_t)mqtt_encode_len(encodedbytes, remaininglength); /* add the control byte and the encoded remaining length */ pkt = malloc(remaininglength + 1 + encodelen); @@ -667,9 +667,9 @@ static CURLcode mqtt_read_publish(struct Curl_easy *data, bool *done) result = CURLE_FILESIZE_EXCEEDED; goto end; } - Curl_pgrsSetDownloadSize(data, remlen); + Curl_pgrsSetDownloadSize(data, (curl_off_t)remlen); data->req.bytecount = 0; - data->req.size = remlen; + data->req.size = (curl_off_t)remlen; mq->npacket = remlen; /* get this many bytes */ FALLTHROUGH(); case MQTT_PUB_REMAIN: { @@ -692,11 +692,11 @@ static CURLcode mqtt_read_publish(struct Curl_easy *data, bool *done) } /* if QoS is set, message contains packet id */ - result = Curl_client_write(data, CLIENTWRITE_BODY, buffer, nread); + result = Curl_client_write(data, CLIENTWRITE_BODY, buffer, (size_t)nread); if(result) goto end; - mq->npacket -= nread; + mq->npacket -= (size_t)nread; if(!mq->npacket) /* no more PUBLISH payload, back to subscribe wait state */ mqstate(data, MQTT_FIRST, MQTT_PUBWAIT); diff --git a/lib/multi.c b/lib/multi.c index ea7961e34a7a53..8d1aef753ef591 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -343,7 +343,7 @@ static size_t hash_fd(void *key, size_t key_length, size_t slots_num) curl_socket_t fd = *((curl_socket_t *) key); (void) key_length; - return (fd % slots_num); + return (size_t)(fd % (curl_socket_t)slots_num); } /* @@ -1492,7 +1492,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, struct, the bit values of the actual underlying poll() implementation may not be the same as the ones in the public libcurl API! */ for(i = 0; i < extra_nfds; i++) { - unsigned r = ufds[curl_nfds + i].revents; + unsigned r = (unsigned)ufds[curl_nfds + i].revents; unsigned short mask = 0; #ifdef USE_WINSOCK curl_socket_t s = extra_fds[i].fd; @@ -1519,7 +1519,7 @@ static CURLMcode multi_wait(struct Curl_multi *multi, mask |= CURL_WAIT_POLLOUT; if(r & POLLPRI) mask |= CURL_WAIT_POLLPRI; - extra_fds[i].revents = mask; + extra_fds[i].revents = (short)mask; } #ifdef USE_WINSOCK @@ -2792,7 +2792,7 @@ CURLMcode curl_multi_perform(struct Curl_multi *multi, int *running_handles) } } while(t); - *running_handles = multi->num_alive; + *running_handles = (int)multi->num_alive; if(CURLM_OK >= returncode) returncode = Curl_update_timer(multi); @@ -3013,7 +3013,8 @@ static CURLMcode singlesocket(struct Curl_multi *multi, } } - entry->action = comboaction; /* store the current action state */ + /* store the current action state */ + entry->action = (unsigned int)comboaction; } /* Check for last_poll.sockets that no longer appear in cur_poll.sockets. @@ -3298,7 +3299,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi, if(first) sigpipe_restore(&pipe_st); - *running_handles = multi->num_alive; + *running_handles = (int)multi->num_alive; return result; } @@ -3603,7 +3604,7 @@ void Curl_expire(struct Curl_easy *data, timediff_t milli, expire_id id) set = Curl_now(); set.tv_sec += (time_t)(milli/1000); /* might be a 64 to 32 bit conversion */ - set.tv_usec += (unsigned int)(milli%1000)*1000; + set.tv_usec += (int)(milli%1000)*1000; if(set.tv_usec >= 1000000) { set.tv_sec++; @@ -3717,12 +3718,12 @@ CURLMcode curl_multi_assign(struct Curl_multi *multi, curl_socket_t s, size_t Curl_multi_max_host_connections(struct Curl_multi *multi) { - return multi ? multi->max_host_connections : 0; + return multi ? (size_t)multi->max_host_connections : 0; } size_t Curl_multi_max_total_connections(struct Curl_multi *multi) { - return multi ? multi->max_total_connections : 0; + return multi ? (size_t)multi->max_total_connections : 0; } /* diff --git a/lib/noproxy.c b/lib/noproxy.c index 62299e28f3bd15..ec61987cdbec14 100644 --- a/lib/noproxy.c +++ b/lib/noproxy.c @@ -79,15 +79,15 @@ UNITTEST bool Curl_cidr6_match(const char *ipv6, unsigned int bits) { #ifdef USE_IPV6 - int bytes; - int rest; + unsigned int bytes; + unsigned int rest; unsigned char address[16]; unsigned char check[16]; if(!bits) bits = 128; - bytes = bits/8; + bytes = bits / 8; rest = bits & 0x07; if(1 != Curl_inet_pton(AF_INET6, ipv6, address)) return FALSE; @@ -152,7 +152,7 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy, if(!endptr) return FALSE; name++; - namelen = endptr - name; + namelen = (size_t)(endptr - name); if(namelen >= sizeof(hostip)) return FALSE; memcpy(hostip, name, namelen); @@ -232,7 +232,7 @@ bool Curl_check_noproxy(const char *name, const char *no_proxy, slash = strchr(check, '/'); /* if the slash is part of this token, use it */ if(slash) { - bits = atoi(slash + 1); + bits = (unsigned int)atoi(slash + 1); *slash = 0; /* null terminate there */ } if(type == TYPE_IPV6) diff --git a/lib/pingpong.c b/lib/pingpong.c index 81576c08c904ba..8342b3fccc6640 100644 --- a/lib/pingpong.c +++ b/lib/pingpong.c @@ -315,13 +315,13 @@ CURLcode Curl_pp_readresp(struct Curl_easy *data, return CURLE_RECV_ERROR; } - result = Curl_dyn_addn(&pp->recvbuf, buffer, gotbytes); + result = Curl_dyn_addn(&pp->recvbuf, buffer, (size_t)gotbytes); if(result) return result; data->req.headerbytecount += (unsigned int)gotbytes; - pp->nread_resp += gotbytes; + pp->nread_resp += (size_t)gotbytes; } do { @@ -330,7 +330,7 @@ CURLcode Curl_pp_readresp(struct Curl_easy *data, if(nl) { /* a newline is CRLF in pp-talk, so the CR is ignored as the line isn't really terminated until the LF comes */ - size_t length = nl - line + 1; + size_t length = (size_t)(nl - line + 1); /* output debug output if that is requested */ #ifdef HAVE_GSSAPI diff --git a/lib/pop3.c b/lib/pop3.c index 85c12cbf2cd3d3..37f4f332535ae1 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -669,10 +669,10 @@ static CURLcode pop3_state_servergreet_resp(struct Curl_easy *data, lt = memchr(line, '<', len); if(lt) /* search the remainder for '>' */ - gt = memchr(lt, '>', len - (lt - line)); + gt = memchr(lt, '>', len - (size_t)(lt - line)); if(gt) { /* the length of the timestamp, including the brackets */ - size_t timestamplen = gt - lt + 1; + size_t timestamplen = (size_t)(gt - lt) + 1; char *at = memchr(lt, '@', timestamplen); /* If the timestamp does not contain '@' it is not (as required by RFC-1939) conformant to the RFC-822 message id syntax, and we @@ -1379,9 +1379,9 @@ static CURLcode pop3_parse_url_options(struct connectdata *conn) if(strncasecompare(key, "AUTH=", 5)) { result = Curl_sasl_parse_url_auth_option(&pop3c->sasl, - value, ptr - value); + value, (size_t)(ptr - value)); - if(result && strncasecompare(value, "+APOP", ptr - value)) { + if(result && strncasecompare(value, "+APOP", (size_t)(ptr - value))) { pop3c->preftype = POP3_TYPE_APOP; pop3c->sasl.prefmech = SASL_AUTH_NONE; result = CURLE_OK; diff --git a/lib/rand.c b/lib/rand.c index c62b1a40323f5f..f7ddaae8605768 100644 --- a/lib/rand.c +++ b/lib/rand.c @@ -269,7 +269,7 @@ CURLcode Curl_rand_alnum(struct Curl_easy *data, unsigned char *rnd, size_t num) { CURLcode result = CURLE_OK; - const int alnumspace = sizeof(alnum) - 1; + const unsigned int alnumspace = sizeof(alnum) - 1; unsigned int r; DEBUGASSERT(num > 1); @@ -282,7 +282,7 @@ CURLcode Curl_rand_alnum(struct Curl_easy *data, unsigned char *rnd, return result; } while(r >= (UINT_MAX - UINT_MAX % alnumspace)); - *rnd++ = alnum[r % alnumspace]; + *rnd++ = (unsigned char)alnum[r % alnumspace]; num--; } *rnd = 0; diff --git a/lib/request.c b/lib/request.c index 26741fa6cb5550..b274db44df02da 100644 --- a/lib/request.c +++ b/lib/request.c @@ -216,7 +216,7 @@ static CURLcode xfer_send(struct Curl_easy *data, if(*pnwritten > hds_len) { size_t body_len = *pnwritten - hds_len; Curl_debug(data, CURLINFO_DATA_OUT, (char *)buf + hds_len, body_len); - data->req.writebytecount += body_len; + data->req.writebytecount += (curl_off_t)body_len; Curl_pgrsSetUploadCounter(data, data->req.writebytecount); } } diff --git a/lib/rtsp.c b/lib/rtsp.c index 89fe4bbb8529d5..f8e9b90d5aa547 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -316,7 +316,9 @@ static CURLcode rtsp_do(struct Curl_easy *data, bool *done) p_session_id = data->set.str[STRING_RTSP_SESSION_ID]; if(!p_session_id && - (rtspreq & ~(RTSPREQ_OPTIONS | RTSPREQ_DESCRIBE | RTSPREQ_SETUP))) { + (rtspreq & ~(Curl_RtspReq)(RTSPREQ_OPTIONS | + RTSPREQ_DESCRIBE | + RTSPREQ_SETUP))) { failf(data, "Refusing to issue an RTSP request [%s] without a session ID.", p_request); result = CURLE_BAD_FUNCTION_ARGUMENT; @@ -956,7 +958,7 @@ CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header) end = start; while(*end && *end != ';' && !ISSPACE(*end)) end++; - idlen = end - start; + idlen = (size_t)(end - start); if(data->set.str[STRING_RTSP_SESSION_ID]) { diff --git a/lib/select.c b/lib/select.c index d92e745a7ff357..1a5ab8572c44e6 100644 --- a/lib/select.c +++ b/lib/select.c @@ -226,7 +226,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */ num++; } - r = Curl_poll(pfd, num, timeout_ms); + r = Curl_poll(pfd, (unsigned int)num, timeout_ms); if(r <= 0) return r; diff --git a/lib/sendf.c b/lib/sendf.c index 847dfea4b538da..2871b0a1ddecfa 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -308,7 +308,7 @@ static CURLcode cw_download_write(struct Curl_easy *data, return result; } /* Update stats, write and report progress */ - data->req.bytecount += nwrite; + data->req.bytecount += (curl_off_t)nwrite; ++data->req.bodywrites; result = Curl_pgrsSetDownloadCounter(data, data->req.bytecount); if(result) @@ -709,7 +709,7 @@ static CURLcode cr_in_read(struct Curl_easy *data, ctx->error_result = CURLE_READ_ERROR; return CURLE_READ_ERROR; } - ctx->read_len += nread; + ctx->read_len += (curl_off_t)nread; if(ctx->total_len >= 0) ctx->seen_eos = (ctx->read_len >= ctx->total_len); *pnread = nread; @@ -778,7 +778,7 @@ static CURLcode cr_in_resume_from(struct Curl_easy *data, ctx->cb_user_data); Curl_set_in_callback(data, false); - passed += actuallyread; + passed += (curl_off_t)actuallyread; if((actuallyread == 0) || (actuallyread > readthisamountnow)) { /* this checks for greater-than only to make sure that the CURL_READFUNC_ABORT return code still aborts */ diff --git a/lib/setopt.c b/lib/setopt.c index f719cc43dde297..4e7757663e9b76 100644 --- a/lib/setopt.c +++ b/lib/setopt.c @@ -942,7 +942,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) break; case CURLOPT_HTTP09_ALLOWED: - arg = va_arg(param, unsigned long); + arg = (long)va_arg(param, unsigned long); if(arg > 1L) return CURLE_BAD_FUNCTION_ARGUMENT; #ifdef USE_HYPER diff --git a/lib/smb.c b/lib/smb.c index 2ce6dbf7fc1101..db439bb20c179f 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -505,7 +505,7 @@ static CURLcode smb_recv_message(struct Curl_easy *data, void **msg) if(!bytes_read) return CURLE_OK; - smbc->got += bytes_read; + smbc->got += (size_t)bytes_read; /* Check for a 32-bit nbt header */ if(smbc->got < sizeof(unsigned int)) @@ -559,7 +559,7 @@ static void smb_format_message(struct Curl_easy *data, struct smb_header *h, h->flags2 = smb_swap16(SMB_FLAGS2_IS_LONG_NAME | SMB_FLAGS2_KNOWS_LONG_NAME); h->uid = smb_swap16(smbc->uid); h->tid = smb_swap16(req->tid); - pid = getpid(); + pid = (unsigned int)getpid(); h->pid_high = smb_swap16((unsigned short)(pid >> 16)); h->pid = smb_swap16((unsigned short) pid); } @@ -671,7 +671,7 @@ static CURLcode smb_send_setup(struct Curl_easy *data) MSGCATNULL(smbc->domain); MSGCATNULL(OS); MSGCATNULL(CLIENTNAME); - byte_count = p - msg.bytes; + byte_count = (size_t)(p - msg.bytes); msg.byte_count = smb_swap16((unsigned short)byte_count); return smb_send_message(data, SMB_COM_SETUP_ANDX, &msg, @@ -699,7 +699,7 @@ static CURLcode smb_send_tree_connect(struct Curl_easy *data) MSGCAT("\\"); MSGCATNULL(smbc->share); MSGCATNULL(SERVICENAME); /* Match any type of service */ - byte_count = p - msg.bytes; + byte_count = (size_t)(p - msg.bytes); msg.byte_count = smb_swap16((unsigned short)byte_count); return smb_send_message(data, SMB_COM_TREE_CONNECT_ANDX, &msg, diff --git a/lib/smtp.c b/lib/smtp.c index a0cb38a8f51ea6..f40a46d3ab7d61 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -695,7 +695,7 @@ static CURLcode smtp_perform_mail(struct Curl_easy *data) /* Prepare the mime data if some. */ if(data->set.mimepost.kind != MIMEKIND_NONE) { /* Use the whole structure as data. */ - data->set.mimepost.flags &= ~MIME_BODY_ONLY; + data->set.mimepost.flags &= ~(unsigned int)MIME_BODY_ONLY; /* Add external headers and mime version. */ curl_mime_headers(&data->set.mimepost, data->set.headers, 0); @@ -1647,7 +1647,7 @@ static CURLcode smtp_parse_url_options(struct connectdata *conn) if(strncasecompare(key, "AUTH=", 5)) result = Curl_sasl_parse_url_auth_option(&smtpc->sasl, - value, ptr - value); + value, (size_t)(ptr - value)); else result = CURLE_URL_MALFORMAT; diff --git a/lib/socks.c b/lib/socks.c index 4ade4eb0207c1e..9747c01b55ed3d 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -217,7 +217,7 @@ static CURLproxycode socks_state_send(struct Curl_cfilter *cf, CURLcode result; nwritten = Curl_conn_cf_send(cf->next, data, (char *)sx->outp, - sx->outstanding, &result); + (size_t)sx->outstanding, &result); if(nwritten <= 0) { if(CURLE_AGAIN == result) { return CURLPX_OK; @@ -248,7 +248,7 @@ static CURLproxycode socks_state_recv(struct Curl_cfilter *cf, CURLcode result; nread = Curl_conn_cf_recv(cf->next, data, (char *)sx->outp, - sx->outstanding, &result); + (size_t)sx->outstanding, &result); if(nread <= 0) { if(CURLE_AGAIN == result) { return CURLPX_OK; @@ -447,7 +447,7 @@ static CURLproxycode do_SOCKS4(struct Curl_cfilter *cf, } sx->outp = socksreq; DEBUGASSERT(packetsize <= sizeof(sx->buffer)); - sx->outstanding = packetsize; + sx->outstanding = (ssize_t)packetsize; sxstate(sx, data, CONNECT_REQ_SENDING); } FALLTHROUGH(); @@ -629,7 +629,7 @@ static CURLproxycode do_SOCKS5(struct Curl_cfilter *cf, sx->outp = socksreq; DEBUGASSERT(idx <= sizeof(sx->buffer)); - sx->outstanding = idx; + sx->outstanding = (ssize_t)idx; presult = socks_state_send(cf, sx, data, CURLPX_SEND_CONNECT, "initial SOCKS5 request"); if(CURLPX_OK != presult) @@ -756,7 +756,7 @@ static CURLproxycode do_SOCKS5(struct Curl_cfilter *cf, len += proxy_password_len; sxstate(sx, data, CONNECT_AUTH_SEND); DEBUGASSERT(len <= sizeof(sx->buffer)); - sx->outstanding = len; + sx->outstanding = (ssize_t)len; sx->outp = socksreq; } FALLTHROUGH(); @@ -951,7 +951,7 @@ static CURLproxycode do_SOCKS5(struct Curl_cfilter *cf, #endif sx->outp = socksreq; DEBUGASSERT(len <= sizeof(sx->buffer)); - sx->outstanding = len; + sx->outstanding = (ssize_t)len; sxstate(sx, data, CONNECT_REQ_SENDING); FALLTHROUGH(); case CONNECT_REQ_SENDING: @@ -1030,7 +1030,7 @@ static CURLproxycode do_SOCKS5(struct Curl_cfilter *cf, if(socksreq[3] == 3) { /* domain name */ int addrlen = (int) socksreq[4]; - len = 5 + addrlen + 2; + len = 5 + (size_t)addrlen + 2; } else if(socksreq[3] == 4) { /* IPv6 */ @@ -1051,7 +1051,7 @@ static CURLproxycode do_SOCKS5(struct Curl_cfilter *cf, #endif if(len > 10) { DEBUGASSERT(len <= sizeof(sx->buffer)); - sx->outstanding = len - 10; /* get the rest */ + sx->outstanding = (ssize_t)len - 10; /* get the rest */ sx->outp = &socksreq[10]; sxstate(sx, data, CONNECT_REQ_READ_MORE); } diff --git a/lib/telnet.c b/lib/telnet.c index 7c2850449470b0..350d9c8d73ddac 100644 --- a/lib/telnet.c +++ b/lib/telnet.c @@ -79,7 +79,7 @@ } while(0) #define CURL_SB_GET(x) ((*x->subpointer++)&0xff) -#define CURL_SB_LEN(x) (x->subend - x->subpointer) +#define CURL_SB_LEN(x) ((size_t)(x->subend - x->subpointer)) /* For posterity: #define CURL_SB_PEEK(x) ((*x->subpointer)&0xff) @@ -823,7 +823,7 @@ static CURLcode check_telnet_options(struct Curl_easy *data) char *arg; char *sep = strchr(option, '='); if(sep) { - olen = sep - option; + olen = (size_t)(sep - option); arg = ++sep; if(str_is_nonascii(arg)) continue; @@ -980,13 +980,14 @@ static void suboption(struct Curl_easy *data) if(len + tmplen < (int)sizeof(temp)-6) { char *s = strchr(v->data, ','); if(!s) - len += msnprintf((char *)&temp[len], sizeof(temp) - len, - "%c%s", CURL_NEW_ENV_VAR, v->data); + len += (size_t)msnprintf((char *)&temp[len], sizeof(temp) - len, + "%c%s", CURL_NEW_ENV_VAR, v->data); else { - size_t vlen = s - v->data; - len += msnprintf((char *)&temp[len], sizeof(temp) - len, - "%c%.*s%c%s", CURL_NEW_ENV_VAR, - (int)vlen, v->data, CURL_NEW_ENV_VALUE, ++s); + size_t vlen = (size_t)(s - v->data); + len += (size_t)msnprintf((char *)&temp[len], sizeof(temp) - len, + "%c%.*s%c%s", CURL_NEW_ENV_VAR, + (int)vlen, v->data, CURL_NEW_ENV_VALUE, + ++s); } } } @@ -1082,7 +1083,7 @@ CURLcode telrcv(struct Curl_easy *data, result = Curl_client_write(data, \ CLIENTWRITE_BODY, \ (char *)&inbuf[startwrite], \ - in-startwrite); \ + (size_t)(in - startwrite)); \ if(result) \ return result; \ } \ @@ -1245,7 +1246,7 @@ static CURLcode send_telnet_data(struct Curl_easy *data, if(nread < 0) return CURLE_TOO_LARGE; - if(memchr(buffer, CURL_IAC, nread)) { + if(memchr(buffer, CURL_IAC, (size_t)nread)) { /* only use the escape buffer when necessary */ Curl_dyn_reset(&tn->out); @@ -1544,7 +1545,7 @@ static CURLcode telnet_do(struct Curl_easy *data, bool *done) while(keepon) { DEBUGF(infof(data, "telnet_do, poll %d fds", poll_cnt)); - switch(Curl_poll(pfd, poll_cnt, interval_ms)) { + switch(Curl_poll(pfd, (unsigned int)poll_cnt, interval_ms)) { case -1: /* error, stop reading */ keepon = FALSE; continue; diff --git a/lib/tftp.c b/lib/tftp.c index 4667ae1e42d6df..28990a2aefffb6 100644 --- a/lib/tftp.c +++ b/lib/tftp.c @@ -321,7 +321,7 @@ static CURLcode tftp_parse_option_ack(struct tftp_state_data *state, while(tmp < ptr + len) { const char *option, *value; - tmp = tftp_option_get(tmp, ptr + len - tmp, &option, &value); + tmp = tftp_option_get(tmp, (size_t)(ptr + len - tmp), &option, &value); if(!tmp) { failf(data, "Malformed ACK packet, rejecting"); return CURLE_TFTP_ILLEGAL; @@ -468,14 +468,14 @@ static CURLcode tftp_send_first(struct tftp_state_data *state, if(result) return result; - if(strlen(filename) > (state->blksize - strlen(mode) - 4)) { + if(strlen(filename) > ((size_t)state->blksize - strlen(mode) - 4)) { failf(data, "TFTP file name too long"); free(filename); return CURLE_TFTP_ILLEGAL; /* too long file name field */ } msnprintf((char *)state->spacket.data + 2, - state->blksize, + (size_t)state->blksize, "%s%c%s%c", filename, '\0', mode, '\0'); sbytes = 4 + strlen(filename) + strlen(mode); @@ -738,7 +738,7 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event) else { /* Re-send the data packet */ sbytes = sendto(state->sockfd, (void *)state->spacket.data, - 4 + state->sbytes, SEND_4TH_ARG, + 4 + (SEND_TYPE_ARG3)state->sbytes, SEND_4TH_ARG, (struct sockaddr *)&state->remote_addr, state->remote_addrlen); /* Check all sbytes were sent */ @@ -774,7 +774,8 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event) state->sbytes = 0; bufptr = (char *)state->spacket.data + 4; do { - result = Curl_client_read(data, bufptr, state->blksize - state->sbytes, + result = Curl_client_read(data, bufptr, + (size_t)(state->blksize - state->sbytes), &cb, &eos); if(result) return result; @@ -783,7 +784,7 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event) } while(state->sbytes < state->blksize && cb); sbytes = sendto(state->sockfd, (void *) state->spacket.data, - 4 + state->sbytes, SEND_4TH_ARG, + 4 + (SEND_TYPE_ARG3)state->sbytes, SEND_4TH_ARG, (struct sockaddr *)&state->remote_addr, state->remote_addrlen); /* Check all sbytes were sent */ @@ -809,7 +810,7 @@ static CURLcode tftp_tx(struct tftp_state_data *state, tftp_event_t event) else { /* Re-send the data packet */ sbytes = sendto(state->sockfd, (void *)state->spacket.data, - 4 + state->sbytes, SEND_4TH_ARG, + 4 + (SEND_TYPE_ARG3)state->sbytes, SEND_4TH_ARG, (struct sockaddr *)&state->remote_addr, state->remote_addrlen); /* Check all sbytes were sent */ @@ -988,14 +989,14 @@ static CURLcode tftp_connect(struct Curl_easy *data, bool *done) need_blksize = TFTP_BLKSIZE_DEFAULT; if(!state->rpacket.data) { - state->rpacket.data = calloc(1, need_blksize + 2 + 2); + state->rpacket.data = calloc(1, (size_t)need_blksize + 2 + 2); if(!state->rpacket.data) return CURLE_OUT_OF_MEMORY; } if(!state->spacket.data) { - state->spacket.data = calloc(1, need_blksize + 2 + 2); + state->spacket.data = calloc(1, (size_t)need_blksize + 2 + 2); if(!state->spacket.data) return CURLE_OUT_OF_MEMORY; @@ -1110,7 +1111,7 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data) fromlen = sizeof(fromaddr); state->rbytes = (int)recvfrom(state->sockfd, (void *)state->rpacket.data, - state->blksize + 4, + (RECV_TYPE_ARG3)state->blksize + 4, 0, (struct sockaddr *)&fromaddr, &fromlen); @@ -1137,7 +1138,7 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data) (NEXT_BLOCKNUM(state->block) == getrpacketblock(&state->rpacket))) { result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)state->rpacket.data + 4, - state->rbytes-4); + (size_t)state->rbytes - 4); if(result) { tftp_state_machine(state, TFTP_EVENT_ERROR); return result; @@ -1148,7 +1149,7 @@ static CURLcode tftp_receive_packet(struct Curl_easy *data) { unsigned short error = getrpacketblock(&state->rpacket); char *str = (char *)state->rpacket.data + 4; - size_t strn = state->rbytes - 4; + size_t strn = (size_t)state->rbytes - 4; state->error = (tftp_error_t)error; if(tftp_strnlen(str, strn) < strn) infof(data, "TFTP error: %s", str); diff --git a/lib/timeval.c b/lib/timeval.c index 5a6727cbc43f6b..f473ef70637c0b 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -52,7 +52,7 @@ struct curltime Curl_now(void) #endif now.tv_sec = milliseconds / 1000; - now.tv_usec = (milliseconds % 1000) * 1000; + now.tv_usec = (int)((milliseconds % 1000) * 1000); } return now; } @@ -95,7 +95,7 @@ struct curltime Curl_now(void) #endif (0 == clock_gettime(CLOCK_MONOTONIC_RAW, &tsnow))) { cnow.tv_sec = tsnow.tv_sec; - cnow.tv_usec = (unsigned int)(tsnow.tv_nsec / 1000); + cnow.tv_usec = (int)(tsnow.tv_nsec / 1000); } else #endif @@ -107,7 +107,7 @@ struct curltime Curl_now(void) #endif (0 == clock_gettime(CLOCK_MONOTONIC, &tsnow))) { cnow.tv_sec = tsnow.tv_sec; - cnow.tv_usec = (unsigned int)(tsnow.tv_nsec / 1000); + cnow.tv_usec = (int)(tsnow.tv_nsec / 1000); } /* ** Even when the configure process has truly detected monotonic clock @@ -118,7 +118,7 @@ struct curltime Curl_now(void) else { (void)gettimeofday(&now, NULL); cnow.tv_sec = now.tv_sec; - cnow.tv_usec = (unsigned int)now.tv_usec; + cnow.tv_usec = (int)now.tv_usec; } #else else { diff --git a/lib/transfer.c b/lib/transfer.c index 744227eb368a8f..e63b68f5da9b31 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -275,7 +275,7 @@ static CURLcode readwrite_data(struct Curl_easy *data, if(k->eos_written) /* already did write this to client, leave */ break; } - total_received += blen; + total_received += (curl_off_t)blen; result = Curl_xfer_write_resp(data, buf, blen, is_eos); if(result || data->req.done) @@ -1244,7 +1244,7 @@ CURLcode Curl_xfer_send(struct Curl_easy *data, *pnwritten = 0; } else if(!result && *pnwritten) - data->info.request_size += *pnwritten; + data->info.request_size += (curl_off_t)*pnwritten; return result; } diff --git a/lib/url.c b/lib/url.c index fc3a4356e41ad5..d2d4d6ce39891b 100644 --- a/lib/url.c +++ b/lib/url.c @@ -1650,7 +1650,7 @@ const struct Curl_handler *Curl_getn_scheme_handler(const char *scheme, unsigned int c = 978; while(l) { c <<= 5; - c += Curl_raw_tolower(*s); + c += (unsigned int)Curl_raw_tolower(*s); s++; l--; } diff --git a/lib/urlapi.c b/lib/urlapi.c index 8e8625d6f22e85..e194bb81cef99c 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -232,7 +232,7 @@ size_t Curl_is_absolute_url(const char *url, char *buf, size_t buflen, be the host name "data" with a specified port number. */ /* the length of the scheme is the name part only */ - size_t len = i; + size_t len = (size_t)i; if(buf) { buf[i] = 0; while(i--) { @@ -466,7 +466,7 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u, /* We could use the login information in the URL so extract it. Only parse options if the handler says we should. Note that 'h' might be NULL! */ - ccode = Curl_parse_login_details(login, ptr - login - 1, + ccode = Curl_parse_login_details(login, (size_t)(ptr - login) - 1, &userp, &passwdp, (h && (h->flags & PROTOPT_URLOPTIONS)) ? &optionsp:NULL); @@ -496,7 +496,7 @@ static CURLUcode parse_hostname_login(struct Curl_URL *u, } /* the host name starts at this offset */ - *offset = ptr - login; + *offset = (size_t)(ptr - login); return CURLUE_OK; out: @@ -538,7 +538,7 @@ UNITTEST CURLUcode Curl_parse_port(struct Curl_URL *u, struct dynbuf *host, if(portptr) { char *rest = NULL; unsigned long port; - size_t keep = portptr - hostname; + size_t keep = (size_t)(portptr - hostname); /* Browser behavior adaptation. If there's a colon with no digits after, just cut off the name there which makes us ignore the colon and just @@ -1112,7 +1112,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) } path = ptr; - pathlen = urllen - (ptr - url); + pathlen = urllen - (size_t)(ptr - url); } if(!uncpath) @@ -1195,7 +1195,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) path = &hostp[hostlen]; /* this pathlen also contains the query and the fragment */ - pathlen = urllen - (path - url); + pathlen = urllen - (size_t)(path - url); if(hostlen) { result = parse_authority(u, hostp, hostlen, flags, &host, schemelen); @@ -1242,7 +1242,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) fragment = strchr(path, '#'); if(fragment) { - fraglen = pathlen - (fragment - path); + fraglen = pathlen - (size_t)(fragment - path); u->fragment_present = TRUE; if(fraglen > 1) { /* skip the leading '#' in the copy but include the terminating null */ @@ -1269,7 +1269,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags) query = memchr(path, '?', pathlen); if(query) { size_t qlen = fragment ? (size_t)(fragment - query) : - pathlen - (query - path); + pathlen - (size_t)(query - path); pathlen -= qlen; u->query_present = TRUE; if(qlen > 1) { diff --git a/lib/ws.c b/lib/ws.c index 86ed5ce17c298e..0f34774c6a5817 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -102,7 +102,7 @@ static unsigned char ws_frame_flags2op(int flags) size_t i; for(i = 0; i < sizeof(WS_FRAMES)/sizeof(WS_FRAMES[0]); ++i) { if(WS_FRAMES[i].flags & flags) - return WS_FRAMES[i].proto_opcode; + return (unsigned char)WS_FRAMES[i].proto_opcode; } return 0; } @@ -171,7 +171,7 @@ static CURLcode ws_dec_read_head(struct ws_decoder *dec, dec->head[0] = *inbuf; Curl_bufq_skip(inraw, 1); - dec->frame_flags = ws_frame_op2flags(dec->head[0]); + dec->frame_flags = ws_frame_op2flags(dec->head[0]); if(!dec->frame_flags) { failf(data, "WS: unknown opcode: %x", dec->head[0]); ws_dec_reset(dec); @@ -350,7 +350,7 @@ static void update_meta(struct websocket *ws, ws->frame.flags = frame_flags; ws->frame.offset = payload_offset; ws->frame.len = cur_len; - ws->frame.bytesleft = (payload_len - payload_offset - cur_len); + ws->frame.bytesleft = payload_len - payload_offset - (curl_off_t)cur_len; } /* WebSockets decoding client writer */ @@ -392,7 +392,7 @@ static ssize_t ws_cw_dec_next(const unsigned char *buf, size_t buflen, struct ws_cw_dec_ctx *ctx = user_data; struct Curl_easy *data = ctx->data; struct websocket *ws = ctx->ws; - curl_off_t remain = (payload_len - (payload_offset + buflen)); + curl_off_t remain = payload_len - (payload_offset + (curl_off_t)buflen); (void)frame_age; if((frame_flags & CURLWS_PING) && !remain) { @@ -560,7 +560,7 @@ static ssize_t ws_enc_write_head(struct Curl_easy *data, return -1; } - opcode = ws_frame_flags2op(flags); + opcode = ws_frame_flags2op((int)flags); if(!opcode) { failf(data, "WS: provided flags not recognized '%x'", flags); *err = CURLE_SEND_ERROR; @@ -867,7 +867,7 @@ static ssize_t ws_client_collect(const unsigned char *buf, size_t buflen, { struct ws_collect *ctx = userp; size_t nwritten; - curl_off_t remain = (payload_len - (payload_offset + buflen)); + curl_off_t remain = payload_len - (payload_offset + (curl_off_t)buflen); if(!ctx->bufidx) { /* first write */ @@ -903,7 +903,7 @@ static ssize_t ws_client_collect(const unsigned char *buf, size_t buflen, memcpy(ctx->buffer + ctx->bufidx, buf, nwritten); ctx->bufidx += nwritten; } - return nwritten; + return (ssize_t)nwritten; } static ssize_t nw_in_recv(void *reader_ctx,