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

@ -95,7 +95,7 @@ static size_t write_cb(char *data, size_t n, size_t l, void *userp)
return n*l;
}
static void add_transfer(CURLM *cm, int i, int *left)
static void add_transfer(CURLM *cm, unsigned int i, int *left)
{
CURL *eh = curl_easy_init();
curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, write_cb);

View file

@ -69,17 +69,15 @@ static int my_seek(void *userp, curl_off_t offset, int origin)
/* read callback function, fread() look alike */
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
{
ssize_t retcode;
unsigned long nread;
size_t nread;
retcode = fread(ptr, size, nmemb, stream);
nread = fread(ptr, size, nmemb, stream);
if(retcode > 0) {
nread = (unsigned long)retcode;
fprintf(stderr, "*** We read %lu bytes from file\n", nread);
if(nread > 0) {
fprintf(stderr, "*** We read %lu bytes from file\n", (unsigned long)nread);
}
return retcode;
return nread;
}
int main(int argc, char **argv)

View file

@ -42,7 +42,7 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
/* open file for writing */
out->stream = fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, cannot open file to write */
return 0; /* failure, cannot open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
}

View file

@ -44,7 +44,7 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb,
/* open file for writing */
out->stream = fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, cannot open file to write */
return 0; /* failure, cannot open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
}

View file

@ -54,7 +54,7 @@ struct transfer {
#define NUM_HANDLES 1000
static
void dump(const char *text, int num, unsigned char *ptr, size_t size,
void dump(const char *text, unsigned int num, unsigned char *ptr, size_t size,
char nohex)
{
size_t i;
@ -66,7 +66,7 @@ void dump(const char *text, int num, unsigned char *ptr, size_t size,
/* without the hex output, we can fit more on screen */
width = 0x40;
fprintf(stderr, "%d %s, %lu bytes (0x%lx)\n",
fprintf(stderr, "%u %s, %lu bytes (0x%lx)\n",
num, text, (unsigned long)size, (unsigned long)size);
for(i = 0; i<size; i += width) {

View file

@ -44,6 +44,13 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
FD_ZERO(&outfd);
FD_ZERO(&errfd);
/* Avoid this warning with pre-2020 Cygwin/MSYS releases:
* warning: conversion to 'long unsigned int' from 'curl_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
*/
#if defined(__GNUC__) && defined(__CYGWIN__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
FD_SET(sockfd, &errfd); /* always check for error */
if(for_recv) {
@ -52,6 +59,9 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
else {
FD_SET(sockfd, &outfd);
}
#if defined(__GNUC__) && defined(__CYGWIN__)
#pragma GCC diagnostic pop
#endif
/* select() returns the number of signalled sockets or -1 */
res = select((int)sockfd + 1, &infd, &outfd, &errfd, &tv);

View file

@ -53,7 +53,7 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb,
/* open file for writing */
out->stream = fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, cannot open file to write */
return 0; /* failure, cannot open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
}