]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib/src/docs/test: improve curl_easy_setopt() calls
authorDaniel Stenberg <daniel@haxx.se>
Wed, 23 Apr 2025 21:13:29 +0000 (23:13 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 23 Apr 2025 21:44:55 +0000 (23:44 +0200)
Fix invokes where the argument was not the correct type.

Closes #17160

22 files changed:
docs/examples/externalsocket.c
docs/examples/ftp-wildcard.c
docs/examples/ipv6.c
docs/examples/sftpget.c
docs/examples/sftpuploadresume.c
src/tool_cfgable.h
tests/http/clients/hx-download.c
tests/http/clients/hx-upload.c
tests/http/clients/tls-session-reuse.c
tests/http/clients/upload-pausing.c
tests/libtest/lib1515.c
tests/libtest/lib1525.c
tests/libtest/lib1526.c
tests/libtest/lib1527.c
tests/libtest/lib1528.c
tests/libtest/lib1529.c
tests/libtest/lib1571.c
tests/libtest/lib1592.c
tests/libtest/lib2301.c
tests/libtest/lib3207.c
tests/libtest/lib678.c
tests/libtest/mk-lib1521.pl

index 142b5af91d0cf59de381f4f4b309acb92d36082d..84c9ba4eb226efdbd8375db5480fd7604fe255c1 100644 (file)
@@ -161,7 +161,7 @@ int main(void)
     /* call this function to set options for the socket */
     curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
 
-    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 
     res = curl_easy_perform(curl);
 
index 53fb76e375226327ce13011557a8638791ada0f5..ddc6e4aae4c6281b37878fcd3607e21109154dd5 100644 (file)
@@ -33,10 +33,10 @@ struct callback_data {
 };
 
 static long file_is_coming(struct curl_fileinfo *finfo,
-                           struct callback_data *data,
+                           void *data,
                            int remains);
 
-static long file_is_downloaded(struct callback_data *data);
+static long file_is_downloaded(void *data);
 
 static size_t write_it(char *buff, size_t size, size_t nmemb,
                        void *cb_data);
@@ -93,10 +93,10 @@ int main(int argc, char **argv)
   return (int)rc;
 }
 
-static long file_is_coming(struct curl_fileinfo *finfo,
-                           struct callback_data *data,
+static long file_is_coming(struct curl_fileinfo *finfo, void *input,
                            int remains)
 {
+  struct callback_data *data = input;
   printf("%3d %40s %10luB ", remains, finfo->filename,
          (unsigned long)finfo->size);
 
@@ -128,8 +128,9 @@ static long file_is_coming(struct curl_fileinfo *finfo,
   return CURL_CHUNK_BGN_FUNC_OK;
 }
 
-static long file_is_downloaded(struct callback_data *data)
+static long file_is_downloaded(void *input)
 {
+  struct callback_data *data = input;
   if(data->output) {
     printf("DOWNLOADED\n");
     fclose(data->output);
index 1b698705d0ccf29fab1780a5c7ffd5c06de82d01..371e0f5573e24ef07a0efab79a42e492173dd8e3 100644 (file)
@@ -35,7 +35,7 @@ int main(void)
 
   curl = curl_easy_init();
   if(curl) {
-    curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
+    curl_easy_setopt(curl, CURLOPT_IPRESOLVE, (long)CURL_IPRESOLVE_V6);
 
     curl_easy_setopt(curl, CURLOPT_URL, "https://curl.se/");
 
index 4d33939a40bf8781e701d41c2b477abda973c471..6b594a1bfecf74f1524ae79ff71a609ff68129bd 100644 (file)
@@ -86,7 +86,7 @@ int main(void)
     /* We activate ssh agent. For this to work you need
        to have ssh-agent running (type set | grep SSH_AGENT to check) or
        pageant on Windows (there is an icon in systray if so) */
-    curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_AGENT);
+    curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, (long)CURLSSH_AUTH_AGENT);
 #endif
 
     /* Switch on full protocol/debug output */
index d0d40a0bc83fc242e35b1842be8675459b9d6b7c..2803da33e0f8f75f2eaedf627212ad100ba9cecb 100644 (file)
@@ -56,10 +56,10 @@ static curl_off_t sftpGetRemoteFileSize(const char *i_remoteFile)
   curl_easy_setopt(curlHandlePtr, CURLOPT_VERBOSE, 1L);
 
   curl_easy_setopt(curlHandlePtr, CURLOPT_URL, i_remoteFile);
-  curl_easy_setopt(curlHandlePtr, CURLOPT_NOPROGRESS, 1);
-  curl_easy_setopt(curlHandlePtr, CURLOPT_NOBODY, 1);
-  curl_easy_setopt(curlHandlePtr, CURLOPT_HEADER, 1);
-  curl_easy_setopt(curlHandlePtr, CURLOPT_FILETIME, 1);
+  curl_easy_setopt(curlHandlePtr, CURLOPT_NOPROGRESS, 1L);
+  curl_easy_setopt(curlHandlePtr, CURLOPT_NOBODY, 1L);
+  curl_easy_setopt(curlHandlePtr, CURLOPT_HEADER, 1L);
+  curl_easy_setopt(curlHandlePtr, CURLOPT_FILETIME, 1L);
 
   result = curl_easy_perform(curlHandlePtr);
   if(CURLE_OK == result) {
index 75fef60c80a15b6a7e2c2a119b01bc2b55064149..4067490fabf850c3cd1a4208c71c22ab8e70c08a 100644 (file)
@@ -202,7 +202,7 @@ struct OperationConfig {
                                      0 is valid. default: CURL_HET_DEFAULT. */
   unsigned long timecond;
   HttpReq httpreq;
-  int proxyver;             /* set to CURLPROXY_HTTP* define */
+  long proxyver;             /* set to CURLPROXY_HTTP* define */
   int ftp_ssl_ccc_mode;
   int ftp_filemethod;
   int default_node_flags;   /* default flags to search for each 'node', which
index 90832c7f31f54c02e80d3bef8cc2aea170958ab4..5990b9ed33430535b4fe644028ef4ba2b8625d9c 100644 (file)
@@ -233,7 +233,7 @@ static int my_progress_cb(void *userdata,
 }
 
 static int setup(CURL *hnd, const char *url, struct transfer *t,
-                 int http_version, struct curl_slist *host,
+                 long http_version, struct curl_slist *host,
                  CURLSH *share, int use_earlydata, int fresh_connect)
 {
   curl_easy_setopt(hnd, CURLOPT_SHARE, share);
index 06df2f4cbfdd56cadff74e4ab242aeeb1001558d..6e391ec3eb3b819a1308bc8edd9b8dc6f40d27a6 100644 (file)
@@ -252,7 +252,7 @@ static int my_progress_cb(void *userdata,
 }
 
 static int setup(CURL *hnd, const char *url, struct transfer *t,
-                 int http_version, struct curl_slist *host,
+                 long http_version, struct curl_slist *host,
                  CURLSH *share, int use_earlydata, int announce_length)
 {
   curl_easy_setopt(hnd, CURLOPT_SHARE, share);
index ef9d84a1310d4ba7192a482467a6c52c1051cd64..ba7c66cab6b963d497cb79a7f2eb2cf9044ff2ab 100644 (file)
@@ -138,7 +138,7 @@ static size_t write_cb(char *ptr, size_t size, size_t nmemb, void *opaque)
 
 static int add_transfer(CURLM *multi, CURLSH *share,
                         struct curl_slist *resolve,
-                        const char *url, int http_version)
+                        const char *url, long http_version)
 {
   CURL *easy;
   CURLMcode mc;
index a9a439bf6bb15a0ea5d0bb0f29694e5d34d9a512..968c9a8e6922fe0464776cc2c4be6846974a2069 100644 (file)
@@ -208,7 +208,7 @@ int main(int argc, char *argv[])
   struct curl_slist *resolve = NULL;
   char resolve_buf[1024];
   char *url, *host = NULL, *port = NULL;
-  int http_version = CURL_HTTP_VERSION_1_1;
+  long http_version = CURL_HTTP_VERSION_1_1;
   int ch;
 
   while((ch = getopt(argc, argv, "V:")) != -1) {
index f772d9e38b2f9ae9cab3c59a91e0432ebf885c49..39e343744c0985a0a9bc19076b3cde3a39fcd936 100644 (file)
@@ -36,7 +36,7 @@
 
 #define TEST_HANG_TIMEOUT 60 * 1000
 
-#define DNS_TIMEOUT 1
+#define DNS_TIMEOUT 1L
 
 static CURLcode do_one_request(CURLM *m, char *URL, char *resolve)
 {
index c8a3063f362f7493e9dea1378e9b16b0a310dde3..e14b766e81ad8c0ff226808f142e5b30cf4573c7 100644 (file)
@@ -75,11 +75,11 @@ CURLcode test(char *URL)
   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
   test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
   test_setopt(curl, CURLOPT_PROXYHEADER, hhl);
-  test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
+  test_setopt(curl, CURLOPT_HEADEROPT, (long)CURLHEADER_UNIFIED);
   test_setopt(curl, CURLOPT_POST, 0L);
   test_setopt(curl, CURLOPT_UPLOAD, 1L);
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
-  test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+  test_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_HTTP);
   test_setopt(curl, CURLOPT_HEADER, 1L);
   test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
index 8093079f553ac898b39f16c3b7b1d6ddb2ede861..3e14c656805f32e31dfa93fc45883cf2f0f87e9e 100644 (file)
@@ -78,11 +78,11 @@ CURLcode test(char *URL)
   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
   test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
   test_setopt(curl, CURLOPT_PROXYHEADER, phl);
-  test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
+  test_setopt(curl, CURLOPT_HEADEROPT, (long)CURLHEADER_SEPARATE);
   test_setopt(curl, CURLOPT_POST, 0L);
   test_setopt(curl, CURLOPT_UPLOAD, 1L);
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
-  test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+  test_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_HTTP);
   test_setopt(curl, CURLOPT_HEADER, 1L);
   test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
index 26581b2a3e364240499c3695190332bc2bcf1fd5..fcc2eb3aa24cef7f578cf25782add066c0dc39cd 100644 (file)
@@ -80,13 +80,13 @@ CURLcode test(char *URL)
   test_setopt(curl, CURLOPT_POST, 0L);
   test_setopt(curl, CURLOPT_UPLOAD, 1L);
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
-  test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+  test_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_HTTP);
   test_setopt(curl, CURLOPT_HEADER, 1L);
   test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
   test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
   test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testdata));
-  test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
+  test_setopt(curl, CURLOPT_HEADEROPT, (long)CURLHEADER_UNIFIED);
 
   res = curl_easy_perform(curl);
 
index 396910a5e923a4d0c5b128262338b2f1e953e2ef..43a6bbb806f7678c18cb2d12aa30e082674fdde1 100644 (file)
@@ -57,9 +57,9 @@ CURLcode test(char *URL)
   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
   test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
   test_setopt(curl, CURLOPT_PROXYHEADER, phl);
-  test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
+  test_setopt(curl, CURLOPT_HEADEROPT, (long)CURLHEADER_SEPARATE);
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
-  test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+  test_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_HTTP);
   test_setopt(curl, CURLOPT_HEADER, 1L);
 
   res = curl_easy_perform(curl);
index 8a1f52cd36347e209500551959c3d6e8a337fe70..51d3eae581493d90a6653dd4e1278971c7463a90 100644 (file)
@@ -49,7 +49,7 @@ CURLcode test(char *URL)
   test_setopt(curl, CURLOPT_URL, bURL);
   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
-  test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+  test_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_HTTP);
   test_setopt(curl, CURLOPT_HEADER, 1L);
 
   res = curl_easy_perform(curl);
index 3a12642efef8f60293556e189c81cde207729ac1..a1d74e3e5c9a6c48619e6697101004123d2bd227 100644 (file)
@@ -50,7 +50,7 @@ CURLcode test(char *URL)
     test_setopt(curl, CURLOPT_POSTFIELDS, "moo");
   }
   if(testno == 1581) {
-    test_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_301);
+    test_setopt(curl, CURLOPT_POSTREDIR, (long)CURL_REDIR_POST_301);
   }
 
   test_setopt(curl, CURLOPT_CUSTOMREQUEST, "IGLOO");
index ebfcf74b5c132f3fa0819f52359e120cefa75774..cb6ee826a8c139f63714353c4af1d7b0c250dc63 100644 (file)
@@ -48,7 +48,7 @@ CURLcode test(char *URL)
   CURL *curl = NULL;
   CURLcode res = CURLE_OK;
   CURLMcode mres;
-  int timeout;
+  long timeout;
 
   global_init(CURL_GLOBAL_ALL);
 
index 15615145f2b6f5b091ff3882452de556fcd9b363..e903e93760ec69c0483df0cce07df4985441e607 100644 (file)
@@ -133,7 +133,7 @@ CURLcode test(char *URL)
     /* use the callback style */
     curl_easy_setopt(curl, CURLOPT_USERAGENT, "webbie-sox/3");
     curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-    curl_easy_setopt(curl, CURLOPT_WS_OPTIONS, CURLWS_RAW_MODE);
+    curl_easy_setopt(curl, CURLOPT_WS_OPTIONS, (long)CURLWS_RAW_MODE);
     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
     curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl);
     res = curl_easy_perform(curl);
index ca87e0061fd07056e1c849ac46b3d5289c68ce0c..882b778829f334541578e6e88a6b223af23edb31 100644 (file)
@@ -103,7 +103,7 @@ test_thread(void *ptr)
 
       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_callback);
       curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr);
-      curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+      curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 
       /* Perform the request, res will get the return code */
       res = curl_easy_perform(curl);
index 9a8ab7670df64c27807822f89e1bef82b3e22f64..3d830354a0c9e02c09d1c635b540dcb79d1dbd43 100644 (file)
@@ -83,7 +83,7 @@ static CURLcode test_cert_blob(const char *url, const char *cafile)
     curl_easy_setopt(curl, CURLOPT_URL,         url);
     curl_easy_setopt(curl, CURLOPT_USERAGENT,   "CURLOPT_CAINFO_BLOB");
     curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS,
-                     CURLSSLOPT_REVOKE_BEST_EFFORT);
+                     (long)CURLSSLOPT_REVOKE_BEST_EFFORT);
 
     blob.data = certdata;
     blob.len = certsize;
index 82970d1d4b9ddf5ba558f64916f6ad50c3f9b37f..9abceae6b3f0d69554401af42355513313931848 100755 (executable)
@@ -341,6 +341,7 @@ CURLcode test(char *URL)
   curl_mime *mimepost = NULL;
   FILE *stream = stderr;
   struct testdata object;
+  CURLU *curlu = (CURLU *)&object;
   char *charp;
   long val;
   curl_off_t oval;
@@ -495,7 +496,7 @@ MOO
             elsif(($name eq "CURLOPT_POSTFIELDS") ||
                   ($name eq "CURLOPT_COPYPOSTFIELDS")) {
                 # set size to zero to avoid it being "illegal"
-                print $fh "  (void)curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);\n";
+                print $fh "  (void)curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0L);\n";
                 print $fh "${fpref} stringpointerextra);\n$fcheck";
             }
             elsif($name eq "CURLOPT_HTTPPOST") {
@@ -507,6 +508,9 @@ MOO
             elsif($name eq "CURLOPT_STDERR") {
               print $fh "${fpref} stream);\n$fcheck";
             }
+            elsif($name eq "CURLOPT_CURLU") {
+              print $fh "${fpref} curlu);\n$fcheck";
+            }
             else {
               print $fh "${fpref} &object);\n$fcheck";
             }
@@ -595,7 +599,7 @@ MOO
 print $fh <<FOOTER
   )
   /* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) */
-  curl_easy_setopt(curl, (CURLoption)1, 0);
+  curl_easy_setopt(curl, (CURLoption)1, 0L);
   res = CURLE_OK;
 test_cleanup:
   curl_easy_cleanup(curl);