build: fix -Wconversion/-Wsign-conversion warnings

Fix remaining warnings in examples and tests which are not suppressed
by the pragma in `lib/curl_setup.h`.

Silence a toolchain issue causing warnings in `FD_SET()` calls with
older Cygwin/MSYS2 builds. Likely fixed on 2020-08-03 by:
https://cygwin.com/git/?p=newlib-cygwin.git;a=commitdiff;h=5717262b8ecfed0f7fab63e2c09c78991e36f9dd

Follow-up to 2dbe75bd7f #12492

Closes #12557
This commit is contained in:
Viktor Szakats 2023-12-19 19:16:03 +00:00
parent 2dbe75bd7f
commit 95a882d268
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
10 changed files with 32 additions and 24 deletions

View file

@ -112,11 +112,11 @@ static size_t my_write_cb(char *buf, size_t nitems, size_t buflen,
void *userdata)
{
struct transfer *t = userdata;
ssize_t nwritten;
size_t nwritten;
if(!t->resumed &&
t->recv_size < t->pause_at &&
((curl_off_t)(t->recv_size + (nitems * buflen)) >= t->pause_at)) {
((t->recv_size + (curl_off_t)(nitems * buflen)) >= t->pause_at)) {
fprintf(stderr, "[t-%d] PAUSE\n", t->idx);
t->paused = 1;
return CURL_WRITEFUNC_PAUSE;
@ -131,11 +131,11 @@ static size_t my_write_cb(char *buf, size_t nitems, size_t buflen,
}
nwritten = fwrite(buf, nitems, buflen, t->out);
if(nwritten < 0) {
if(nwritten < buflen) {
fprintf(stderr, "[t-%d] write failure\n", t->idx);
return 0;
}
t->recv_size += nwritten;
t->recv_size += (curl_off_t)nwritten;
return (size_t)nwritten;
}
@ -171,7 +171,7 @@ static void usage(const char *msg)
" download a url with following options:\n"
" -m number max parallel downloads\n"
" -n number total downloads\n"
" -p number pause transfer after `number` response bytes\n"
" -P number pause transfer after `number` response bytes\n"
);
}
@ -185,7 +185,7 @@ int main(int argc, char *argv[])
const char *url;
size_t i, n, max_parallel = 1;
size_t active_transfers;
long pause_offset = 0;
size_t pause_offset = 0;
int abort_paused = 0;
struct transfer *t;
int ch;
@ -205,7 +205,7 @@ int main(int argc, char *argv[])
transfer_count = (size_t)strtol(optarg, NULL, 10);
break;
case 'P':
pause_offset = strtol(optarg, NULL, 10);
pause_offset = (size_t)strtol(optarg, NULL, 10);
break;
default:
usage("invalid option");
@ -234,7 +234,7 @@ int main(int argc, char *argv[])
for(i = 0; i < transfer_count; ++i) {
t = &transfers[i];
t->idx = (int)i;
t->pause_at = (curl_off_t)pause_offset * i;
t->pause_at = (curl_off_t)(pause_offset * i);
}
n = (max_parallel < transfer_count)? max_parallel : transfer_count;

View file

@ -497,7 +497,7 @@ static curl_socket_t mqttit(curl_socket_t fd)
unsigned short packet_id;
size_t payload_len;
size_t client_id_length;
unsigned int topic_len;
size_t topic_len;
size_t remaining_length = 0;
size_t bytes = 0; /* remaining length field size in bytes */
char client_id[MAX_CLIENT_ID_LENGTH];
@ -635,7 +635,7 @@ static curl_socket_t mqttit(curl_socket_t fd)
/* two bytes topic length */
topic_len = (size_t)(buffer[2] << 8) | buffer[3];
if(topic_len != (remaining_length - 5)) {
logmsg("Wrong topic length, got %u expected %zu",
logmsg("Wrong topic length, got %zu expected %zu",
topic_len, remaining_length - 5);
goto end;
}

View file

@ -620,7 +620,7 @@ static curl_socket_t sockit(curl_socket_t fd)
memcpy(&response[SOCKS5_BNDADDR + len],
&buffer[SOCKS5_DSTADDR + len], sizeof(socksport));
rc = (send)(fd, (char *)response, len + 6, 0);
rc = (send)(fd, (char *)response, (size_t)(len + 6), 0);
if(rc != (len + 6)) {
logmsg("Sending connect response failed!");
return CURL_SOCKET_BAD;