]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
examples: fix/silence `-Wsign-conversion`
authorViktor Szakats <commit@vsz.me>
Sat, 27 Apr 2024 19:09:01 +0000 (21:09 +0200)
committerViktor Szakats <commit@vsz.me>
Sat, 11 May 2024 09:11:32 +0000 (11:11 +0200)
- extend `FD_SET()` hack to all platforms (was only Cygwin).
  Warnings may also happen in other envs, e.g. OmniOS.
  Ref: https://github.com/libssh2/libssh2/actions/runs/8854199687/job/24316762831#step:3:2021

- tidy-up `CURLcode` vs `int` use.

- cast an unsigned to `long` before passing to `curl_easy_setopt()`.

Cherry-picked from #13489
Follow-up to 3829759bd042c03225ae862062560f568ba1a231 #12489
Closes #13501

docs/examples/address-scope.c
docs/examples/ftp-wildcard.c
docs/examples/sendrecv.c
docs/examples/websocket.c

index 5650fdb230a1894e55dbbf8a03fa8cac938cc5a2..a4ae26539172bbc9f9bbf41de01fa0d347e52de0 100644 (file)
@@ -44,7 +44,7 @@ int main(void)
     long my_scope_id;
     curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
 
-    my_scope_id = if_nametoindex("eth0");
+    my_scope_id = (long)if_nametoindex("eth0");
     curl_easy_setopt(curl, CURLOPT_ADDRESS_SCOPE, my_scope_id);
 
     /* Perform the request, res gets the return code */
index 8a1b3c88f2f9675fa98957313a97cc2d1f6b975d..53fb76e375226327ce13011557a8638791ada0f5 100644 (file)
@@ -50,9 +50,9 @@ int main(int argc, char **argv)
   struct callback_data data = { 0 };
 
   /* global initialization */
-  int rc = curl_global_init(CURL_GLOBAL_ALL);
+  CURLcode rc = curl_global_init(CURL_GLOBAL_ALL);
   if(rc)
-    return rc;
+    return (int)rc;
 
   /* initialization of easy handle */
   handle = curl_easy_init();
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
 
   curl_easy_cleanup(handle);
   curl_global_cleanup();
-  return rc;
+  return (int)rc;
 }
 
 static long file_is_coming(struct curl_fileinfo *finfo,
index 0b7e86a3f098f818c11e03d18a0f02ec5def5403..379b20dae60a27e4f297ecefe38e7544d06b4c37 100644 (file)
@@ -48,7 +48,7 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
  * 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__)
+#if defined(__GNUC__)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wsign-conversion"
 #endif
@@ -60,7 +60,7 @@ 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__)
+#if defined(__GNUC__)
 #pragma GCC diagnostic pop
 #endif
 
index 039b4f8b9588bf3f10f1691998bc4ac2ada29fba..4487b50098e03bfdd61f20df88a55b05c397333e 100644 (file)
@@ -68,16 +68,13 @@ static int recv_pong(CURL *curl, const char *expected_payload)
   return (int)result;
 }
 
-static int recv_any(CURL *curl)
+static CURLcode recv_any(CURL *curl)
 {
   size_t rlen;
   const struct curl_ws_frame *meta;
   char buffer[256];
-  CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
-  if(result)
-    return result;
 
-  return 0;
+  return curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
 }
 
 /* close the connection */