Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vszakats committed Apr 27, 2024
1 parent 28914be commit 367ea4a
Show file tree
Hide file tree
Showing 52 changed files with 258 additions and 240 deletions.
12 changes: 6 additions & 6 deletions lib/altsvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/altsvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct altsvc {
struct althost dst;
time_t expires;
bool persist;
int prio;
unsigned int prio;
struct Curl_llist_element node;
};

Expand Down
10 changes: 5 additions & 5 deletions lib/bufq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions lib/cf-https-connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/cf-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/cfilters.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 4 additions & 3 deletions lib/content_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions lib/cookie.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions lib/curl_ntlm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 9 additions & 8 deletions lib/curl_trc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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, ...)
Expand All @@ -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);
}
}

Expand Down
16 changes: 8 additions & 8 deletions lib/doh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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 */
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/dynhds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion lib/easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 367ea4a

Please sign in to comment.