Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: silence -Wsign-conversion, tidy-ups, fixes #13481

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
0ad8b49
lib altsvc
vszakats Apr 24, 2024
3c270a3
lib altsvc switch prio to unsigned int
vszakats Apr 27, 2024
d9231e3
lib asyn-ares
vszakats Apr 27, 2024
2511495
lib asyn-thread win32
vszakats Apr 27, 2024
f7530f5
lib bufq
vszakats Apr 25, 2024
8c17732
lib cf-h2-proxy
vszakats Apr 27, 2024
b94206b
lib cf-socket
vszakats Apr 25, 2024
9606299
lib c-hyper
vszakats Apr 28, 2024
3391e21
lib cfilters
vszakats Apr 25, 2024
29321ae
lib content_encoding
vszakats Apr 25, 2024
8d03ece
lib cookie
vszakats Apr 25, 2024
e63dbe5
lib curl_addrinfo mingw
vszakats Apr 28, 2024
8153c63
lib curl_fnmatch
vszakats Apr 27, 2024
ae40d07
lib curl_gethostname
vszakats Apr 28, 2024
a8317f7
lib curl_gssapi
vszakats Apr 27, 2024
82db7d7
lib curl_multibyte
vszakats Apr 27, 2024
26af888
lib curl_ntlm_core
vszakats Apr 25, 2024
0390180
lib curl_path
vszakats Apr 27, 2024
de4f8f9
lib curl_sspi
vszakats Apr 27, 2024
fa41c91
lib curl_trc
vszakats Apr 25, 2024
d0ce612
lib dynhds
vszakats Apr 25, 2024
d2c89b1
lib doh
vszakats Apr 25, 2024
22e9405
lib nonblock
vszakats Apr 28, 2024
4245995
lib inet_ntop
vszakats Apr 28, 2024
01ac885
lib inet_ntop.h win32
vszakats Apr 28, 2024
beff682
lib inet_pton
vszakats Apr 28, 2024
e9a8486
lib easy
vszakats Apr 25, 2024
bb3c232
lib escape
vszakats Apr 25, 2024
f98e79a
lib file
vszakats Apr 25, 2024
837b441
lib smtp
vszakats Apr 25, 2024
2700e8e
lib setopt
vszakats Apr 25, 2024
14e2f87
lib select
vszakats Apr 25, 2024
af2801e
lib select FD_SET/FD_ISSET workaround
vszakats Apr 28, 2024
efedcd4
lib request
vszakats Apr 25, 2024
5904160
lib pingpong
vszakats Apr 26, 2024
81c4a27
lib formdata
vszakats Apr 26, 2024
dc23139
lib ftp
vszakats Apr 26, 2024
e1b531a
lib getinfo
vszakats Apr 26, 2024
8fb92aa
lib gopher
vszakats Apr 26, 2024
796dd44
lib hash
vszakats Apr 26, 2024
e2b566a
lib headers
vszakats Apr 26, 2024
3e7cb8c
lib hostip
vszakats Apr 26, 2024
44cd7dc
lib http
vszakats Apr 26, 2024
0c58246
lib http1
vszakats Apr 26, 2024
3c557c7
lib http2
vszakats Apr 27, 2024
f25aa4c
lib http_aws_sigv4
vszakats Apr 26, 2024
d7002be
lib http_chunks
vszakats Apr 26, 2024
ac91fea
lib http_digest
vszakats Apr 26, 2024
cc4018e
lib imap
vszakats Apr 26, 2024
5dc7ca8
lib timeval
vszakats Apr 27, 2024
7ac27b2
lib transfer
vszakats Apr 27, 2024
1223fe7
lib url
vszakats Apr 27, 2024
cf0c465
lib urlapi
vszakats Apr 27, 2024
34d8b0d
lib krb5
vszakats Apr 27, 2024
7286832
lib openldap
vszakats Apr 27, 2024
54807a8
lib ldap
vszakats Apr 27, 2024
c385829
lib pop3
vszakats Apr 27, 2024
023d545
lib rand
vszakats Apr 27, 2024
30dd5d1
lib rtsp
vszakats Apr 27, 2024
218b496
lib noproxy
vszakats Apr 27, 2024
1855987
lib sendf
vszakats Apr 27, 2024
89cbb56
lib smb
vszakats Apr 27, 2024
37276b0
lib memdebug.h
vszakats Apr 28, 2024
9f73afa
lib mime
vszakats Apr 27, 2024
e6d0ff9
lib mqtt
vszakats Apr 27, 2024
e619b52
lib multi
vszakats Apr 27, 2024
bba4d94
lib multi suppress sign-conversion for FD_SET
vszakats Apr 28, 2024
263c630
lib socketpair
vszakats Apr 28, 2024
deaf629
lib socks
vszakats Apr 27, 2024
1d7dbca
lib socks_gssapi
vszakats Apr 28, 2024
a105fc9
lib socks_sspi
vszakats Apr 28, 2024
cdeb359
lib strerror
vszakats Apr 28, 2024
0687bbe
lib telnet
vszakats Apr 27, 2024
755d7dd
lib tftp
vszakats Apr 27, 2024
28dde17
lib tftp win32
vszakats Apr 28, 2024
fbb7e11
lib ws
vszakats Apr 27, 2024
3c39ee1
lib version
vszakats Apr 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this kind of typecast is perhaps the biggest sign that we should not use this warning option. The diff between two char * should be possible to store in a size_t without a typecast.

Or put another way: do these typecasts really help? They will make writing new code a little more awkward.

Copy link
Member Author

@vszakats vszakats Apr 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It pinpoints all the places where the result might be negative,
but the code assumes positive. For the strchr() pattern and manual
versions of it, this isn't really useful, but may be in the rest.

I assumed that all existing code is correct, but this isn't readily obvious
while reviewing the 442 cases.

A cast adds a signal that sign conversions were consious decisions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It pinpoints all the places where the result might be negative, but the code assumes positive

The code does not assume this, it knows. The logic is quite easy to follow.

In this and similar cases, this typecast does not add anything at all to a reader. In fact, it is mostly confusing to me since a pointer-delta should already be possible to store in a `size_t' just fine. Should it not?

Have you detected and corrected any actual errors with this exercise?

Copy link
Member Author

@vszakats vszakats Apr 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some, that were obvious and low-hanging, yes.

But, I try not to touch the actual logic, first because it'd take a very long time to explore each rabbit hole, and second it'd make the patch confusing IMO. Also, it's highly likely the code is correct unless proven otherwise.

What I find that it's difficult to deduct from local contexts that the code is handling the implicit sign conversions conciously.

Am I mistaken that e.g. a 100 - 1000 pointer delta would result in an underflow and make the result a very high number when handled as an unsigned size_t?

The other thing driving this is that this is one the few warnings actually recommended by OpenSSF. Assuming they know what they are saying, this might actually be useful, though of course there is nothing saying we must follow their recommendations.

*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
2 changes: 1 addition & 1 deletion lib/asyn-ares.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static int waitperform(struct Curl_easy *data, timediff_t timeout_ms)
}

if(num) {
nfds = Curl_poll(pfd, num, timeout_ms);
nfds = Curl_poll(pfd, (unsigned int)num, timeout_ms);
if(nfds < 0)
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/asyn-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ static bool init_resolve_thread(struct Curl_easy *data,
NULL, &td->tsd.w8.overlapped,
&query_complete, &td->tsd.w8.cancel_ev);
if(err != WSA_IO_PENDING)
query_complete(err, 0, &td->tsd.w8.overlapped);
query_complete((DWORD)err, 0, &td->tsd.w8.overlapped);
return TRUE;
}
}
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
8 changes: 4 additions & 4 deletions lib/c-hyper.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ CURLcode Curl_hyper_header(struct Curl_easy *data, hyper_headers *headers,
if(!p)
/* this is fine if we already added at least one header */
return numh ? CURLE_OK : CURLE_BAD_FUNCTION_ARGUMENT;
nlen = p - n;
nlen = (size_t)(p - n);
p++; /* move past the colon */
while(*p == ' ')
p++;
Expand All @@ -587,8 +587,8 @@ CURLcode Curl_hyper_header(struct Curl_easy *data, hyper_headers *headers,
}
else
linelen = 2; /* CRLF ending */
linelen += (p - n);
vlen = p - v;
linelen += (size_t)(p - n);
vlen = (size_t)(p - v);

if(HYPERE_OK != hyper_headers_add(headers, (uint8_t *)n, nlen,
(uint8_t *)v, vlen)) {
Expand Down Expand Up @@ -670,7 +670,7 @@ static int uploadstreamed(void *userdata, hyper_context *ctx,
}
/* increasing the writebytecount here is a little premature but we
don't know exactly when the body is sent */
data->req.writebytecount += fillcount;
data->req.writebytecount += (curl_off_t)fillcount;
Curl_pgrsSetUploadCounter(data, data->req.writebytecount);
rc = HYPER_POLL_READY;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/cf-h2-proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ static ssize_t cf_h2_proxy_send(struct Curl_cfilter *cf,
/* Unable to send all data, due to connection blocked or H2 window
* exhaustion. Data is left in our stream buffer, or nghttp2's internal
* frame buffer or our network out buffer. */
size_t rwin = nghttp2_session_get_stream_remote_window_size(
size_t rwin = (size_t)nghttp2_session_get_stream_remote_window_size(
ctx->h2, ctx->tunnel.stream_id);
if(rwin == 0) {
/* H2 flow window exhaustion.
Expand All @@ -1433,7 +1433,7 @@ static ssize_t cf_h2_proxy_send(struct Curl_cfilter *cf,
/* Whatever the cause, we need to return CURL_EAGAIN for this call.
* We have unwritten state that needs us being invoked again and EAGAIN
* is the only way to ensure that. */
ctx->tunnel.upload_blocked_len = nwritten;
ctx->tunnel.upload_blocked_len = (size_t)nwritten;
CURL_TRC_CF(data, cf, "[%d] cf_send(len=%zu) BLOCK: win %u/%zu "
"blocked_len=%zu",
ctx->tunnel.stream_id, len,
Expand Down
18 changes: 10 additions & 8 deletions lib/cf-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ tcpkeepalive(struct Curl_easy *data,
vals.onoff = 1;
optval = curlx_sltosi(data->set.tcp_keepidle);
KEEPALIVE_FACTOR(optval);
vals.keepalivetime = optval;
vals.keepalivetime = (u_long)optval;
optval = curlx_sltosi(data->set.tcp_keepintvl);
KEEPALIVE_FACTOR(optval);
vals.keepaliveinterval = optval;
vals.keepaliveinterval = (u_long)optval;
if(WSAIoctl(sockfd, SIO_KEEPALIVE_VALS, (LPVOID) &vals, sizeof(vals),
NULL, 0, &dummy, NULL, NULL) != 0) {
infof(data, "Failed to set SIO_KEEPALIVE_VALS on fd "
Expand Down Expand Up @@ -249,7 +249,7 @@ void Curl_sock_assign_addr(struct Curl_sockaddr_ex *dest,
dest->protocol = IPPROTO_UDP;
break;
}
dest->addrlen = ai->ai_addrlen;
dest->addrlen = (unsigned int)ai->ai_addrlen;

if(dest->addrlen > sizeof(struct Curl_sockaddr_storage))
dest->addrlen = sizeof(struct Curl_sockaddr_storage);
Expand Down Expand Up @@ -958,7 +958,7 @@ static CURLcode set_remote_ip(struct Curl_cfilter *cf,
struct cf_socket_ctx *ctx = cf->ctx;

/* store remote address and port used in this connection attempt */
if(!Curl_addr2string(&ctx->addr.sa_addr, ctx->addr.addrlen,
if(!Curl_addr2string(&ctx->addr.sa_addr, (curl_socklen_t)ctx->addr.addrlen,
ctx->ip.remote_ip, &ctx->ip.remote_port)) {
char buffer[STRERROR_LEN];

Expand Down Expand Up @@ -1123,7 +1123,8 @@ static int do_connect(struct Curl_cfilter *cf, struct Curl_easy *data,
#endif
}
else {
rc = connect(ctx->sock, &ctx->addr.sa_addr, ctx->addr.addrlen);
rc = connect(ctx->sock, &ctx->addr.sa_addr,
(curl_socklen_t)ctx->addr.addrlen);
}
return rc;
}
Expand Down Expand Up @@ -1299,7 +1300,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 Expand Up @@ -1630,7 +1631,8 @@ static CURLcode cf_udp_setup_quic(struct Curl_cfilter *cf,
/* On macOS OpenSSL QUIC fails on connected sockets.
* see: <https://github.com/openssl/openssl/issues/23251> */
#else
rc = connect(ctx->sock, &ctx->addr.sa_addr, ctx->addr.addrlen);
rc = connect(ctx->sock, &ctx->addr.sa_addr,
(curl_socklen_t)ctx->addr.addrlen);
if(-1 == rc) {
return socket_connect_result(data, ctx->ip.remote_ip, SOCKERRNO);
}
Expand Down Expand Up @@ -1890,7 +1892,7 @@ static void set_accepted_remote_ip(struct Curl_cfilter *cf,
ctx->ip.remote_ip[0] = 0;
ctx->ip.remote_port = 0;
plen = sizeof(ssrem);
memset(&ssrem, 0, plen);
memset(&ssrem, 0, (size_t)plen);
if(getpeername(ctx->sock, (struct sockaddr*) &ssrem, &plen)) {
int error = SOCKERRNO;
failf(data, "getpeername() failed with errno %d: %s",
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
11 changes: 6 additions & 5 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 @@ -536,13 +537,13 @@ static CURLcode gzip_do_write(struct Curl_easy *data,
/* Append the new block of data to the previous one */
memcpy(z->next_in + z->avail_in - nbytes, buf, nbytes);

switch(check_gzip_header(z->next_in, z->avail_in, &hlen)) {
switch(check_gzip_header(z->next_in, (ssize_t)z->avail_in, &hlen)) {
case GZIP_OK:
/* This is the zlib stream data */
free(z->next_in);
/* Don't point into the malloced block since we just freed it */
z->next_in = (Bytef *) buf + hlen + nbytes - z->avail_in;
z->avail_in = (uInt) (z->avail_in - hlen);
z->avail_in = z->avail_in - (uInt)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
17 changes: 9 additions & 8 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 @@ -262,8 +262,9 @@ static size_t cookie_hash_domain(const char *domain, const size_t len)
size_t h = 5381;

while(domain < end) {
size_t j = (size_t)Curl_raw_toupper(*domain++);
h += h << 5;
h ^= Curl_raw_toupper(*domain++);
h ^= j;
}

return (h % COOKIE_HASH_SIZE);
Expand Down Expand Up @@ -436,7 +437,7 @@ static bool bad_domain(const char *domain, size_t len)
/* there must be a dot present, but that dot must not be a trailing dot */
char *dot = memchr(domain, '.', len);
if(dot) {
size_t i = dot - domain;
size_t i = (size_t)(dot - domain);
if((len - i) > 1)
/* the dot is not the last byte */
return FALSE;
Expand Down Expand Up @@ -820,9 +821,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 +1088,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 +1647,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
8 changes: 8 additions & 0 deletions lib/curl_addrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ Curl_he2ai(const struct hostent *he, int port)
addr = (void *)ai->ai_addr; /* storage area for this info */

memcpy(&addr->sin_addr, curr, sizeof(struct in_addr));
#ifdef __MINGW32__
addr->sin_family = (short)(he->h_addrtype);
#else
addr->sin_family = (CURL_SA_FAMILY_T)(he->h_addrtype);
#endif
addr->sin_port = htons((unsigned short)port);
break;

Expand All @@ -326,7 +330,11 @@ Curl_he2ai(const struct hostent *he, int port)
addr6 = (void *)ai->ai_addr; /* storage area for this info */

memcpy(&addr6->sin6_addr, curr, sizeof(struct in6_addr));
#ifdef __MINGW32__
addr6->sin6_family = (short)(he->h_addrtype);
#else
addr6->sin6_family = (CURL_SA_FAMILY_T)(he->h_addrtype);
#endif
addr6->sin6_port = htons((unsigned short)port);
break;
#endif
Expand Down
2 changes: 1 addition & 1 deletion lib/curl_fnmatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static int parsekeyword(unsigned char **pattern, unsigned char *charset)
unsigned char *p = *pattern;
bool found = FALSE;
for(i = 0; !found; i++) {
char c = *p++;
char c = (char)*p++;
if(i >= KEYLEN)
return SETCHARSET_FAIL;
switch(state) {
Expand Down
2 changes: 1 addition & 1 deletion lib/curl_gethostname.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int Curl_gethostname(char * const name, GETHOSTNAME_TYPE_ARG2 namelen)
/* Override host name when environment variable CURL_GETHOSTNAME is set */
const char *force_hostname = getenv("CURL_GETHOSTNAME");
if(force_hostname) {
strncpy(name, force_hostname, namelen);
strncpy(name, force_hostname, (size_t)namelen);
err = 0;
}
else {
Expand Down