lib/src/docs/test: improve curl_easy_setopt() calls

Fix invokes where the argument was not the correct type.

Closes #17160
This commit is contained in:
Daniel Stenberg 2025-04-23 23:13:29 +02:00
parent 179aeeaf22
commit f9f1a15699
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
22 changed files with 39 additions and 34 deletions

View File

@ -161,7 +161,7 @@ int main(void)
/* call this function to set options for the socket */ /* call this function to set options for the socket */
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback); 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); res = curl_easy_perform(curl);

View File

@ -33,10 +33,10 @@ struct callback_data {
}; };
static long file_is_coming(struct curl_fileinfo *finfo, static long file_is_coming(struct curl_fileinfo *finfo,
struct callback_data *data, void *data,
int remains); 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, static size_t write_it(char *buff, size_t size, size_t nmemb,
void *cb_data); void *cb_data);
@ -93,10 +93,10 @@ int main(int argc, char **argv)
return (int)rc; return (int)rc;
} }
static long file_is_coming(struct curl_fileinfo *finfo, static long file_is_coming(struct curl_fileinfo *finfo, void *input,
struct callback_data *data,
int remains) int remains)
{ {
struct callback_data *data = input;
printf("%3d %40s %10luB ", remains, finfo->filename, printf("%3d %40s %10luB ", remains, finfo->filename,
(unsigned long)finfo->size); (unsigned long)finfo->size);
@ -128,8 +128,9 @@ static long file_is_coming(struct curl_fileinfo *finfo,
return CURL_CHUNK_BGN_FUNC_OK; 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) { if(data->output) {
printf("DOWNLOADED\n"); printf("DOWNLOADED\n");
fclose(data->output); fclose(data->output);

View File

@ -35,7 +35,7 @@ int main(void)
curl = curl_easy_init(); curl = curl_easy_init();
if(curl) { 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/"); curl_easy_setopt(curl, CURLOPT_URL, "https://curl.se/");

View File

@ -86,7 +86,7 @@ int main(void)
/* We activate ssh agent. For this to work you need /* We activate ssh agent. For this to work you need
to have ssh-agent running (type set | grep SSH_AGENT to check) or to have ssh-agent running (type set | grep SSH_AGENT to check) or
pageant on Windows (there is an icon in systray if so) */ 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 #endif
/* Switch on full protocol/debug output */ /* Switch on full protocol/debug output */

View 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_VERBOSE, 1L);
curl_easy_setopt(curlHandlePtr, CURLOPT_URL, i_remoteFile); curl_easy_setopt(curlHandlePtr, CURLOPT_URL, i_remoteFile);
curl_easy_setopt(curlHandlePtr, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curlHandlePtr, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curlHandlePtr, CURLOPT_NOBODY, 1); curl_easy_setopt(curlHandlePtr, CURLOPT_NOBODY, 1L);
curl_easy_setopt(curlHandlePtr, CURLOPT_HEADER, 1); curl_easy_setopt(curlHandlePtr, CURLOPT_HEADER, 1L);
curl_easy_setopt(curlHandlePtr, CURLOPT_FILETIME, 1); curl_easy_setopt(curlHandlePtr, CURLOPT_FILETIME, 1L);
result = curl_easy_perform(curlHandlePtr); result = curl_easy_perform(curlHandlePtr);
if(CURLE_OK == result) { if(CURLE_OK == result) {

View File

@ -202,7 +202,7 @@ struct OperationConfig {
0 is valid. default: CURL_HET_DEFAULT. */ 0 is valid. default: CURL_HET_DEFAULT. */
unsigned long timecond; unsigned long timecond;
HttpReq httpreq; HttpReq httpreq;
int proxyver; /* set to CURLPROXY_HTTP* define */ long proxyver; /* set to CURLPROXY_HTTP* define */
int ftp_ssl_ccc_mode; int ftp_ssl_ccc_mode;
int ftp_filemethod; int ftp_filemethod;
int default_node_flags; /* default flags to search for each 'node', which int default_node_flags; /* default flags to search for each 'node', which

View File

@ -233,7 +233,7 @@ static int my_progress_cb(void *userdata,
} }
static int setup(CURL *hnd, const char *url, struct transfer *t, 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) CURLSH *share, int use_earlydata, int fresh_connect)
{ {
curl_easy_setopt(hnd, CURLOPT_SHARE, share); curl_easy_setopt(hnd, CURLOPT_SHARE, share);

View File

@ -252,7 +252,7 @@ static int my_progress_cb(void *userdata,
} }
static int setup(CURL *hnd, const char *url, struct transfer *t, 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) CURLSH *share, int use_earlydata, int announce_length)
{ {
curl_easy_setopt(hnd, CURLOPT_SHARE, share); curl_easy_setopt(hnd, CURLOPT_SHARE, share);

View 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, static int add_transfer(CURLM *multi, CURLSH *share,
struct curl_slist *resolve, struct curl_slist *resolve,
const char *url, int http_version) const char *url, long http_version)
{ {
CURL *easy; CURL *easy;
CURLMcode mc; CURLMcode mc;

View File

@ -208,7 +208,7 @@ int main(int argc, char *argv[])
struct curl_slist *resolve = NULL; struct curl_slist *resolve = NULL;
char resolve_buf[1024]; char resolve_buf[1024];
char *url, *host = NULL, *port = NULL; char *url, *host = NULL, *port = NULL;
int http_version = CURL_HTTP_VERSION_1_1; long http_version = CURL_HTTP_VERSION_1_1;
int ch; int ch;
while((ch = getopt(argc, argv, "V:")) != -1) { while((ch = getopt(argc, argv, "V:")) != -1) {

View File

@ -36,7 +36,7 @@
#define TEST_HANG_TIMEOUT 60 * 1000 #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) static CURLcode do_one_request(CURLM *m, char *URL, char *resolve)
{ {

View File

@ -75,11 +75,11 @@ CURLcode test(char *URL)
test_setopt(curl, CURLOPT_PROXY, libtest_arg2); test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl); test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_PROXYHEADER, 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_POST, 0L);
test_setopt(curl, CURLOPT_UPLOAD, 1L); test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 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_HEADER, 1L);
test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite); test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
test_setopt(curl, CURLOPT_READFUNCTION, read_callback); test_setopt(curl, CURLOPT_READFUNCTION, read_callback);

View File

@ -78,11 +78,11 @@ CURLcode test(char *URL)
test_setopt(curl, CURLOPT_PROXY, libtest_arg2); test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl); test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_PROXYHEADER, phl); 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_POST, 0L);
test_setopt(curl, CURLOPT_UPLOAD, 1L); test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 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_HEADER, 1L);
test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite); test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
test_setopt(curl, CURLOPT_READFUNCTION, read_callback); test_setopt(curl, CURLOPT_READFUNCTION, read_callback);

View File

@ -80,13 +80,13 @@ CURLcode test(char *URL)
test_setopt(curl, CURLOPT_POST, 0L); test_setopt(curl, CURLOPT_POST, 0L);
test_setopt(curl, CURLOPT_UPLOAD, 1L); test_setopt(curl, CURLOPT_UPLOAD, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 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_HEADER, 1L);
test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite); test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
test_setopt(curl, CURLOPT_READFUNCTION, read_callback); test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L); test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testdata)); 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); res = curl_easy_perform(curl);

View File

@ -57,9 +57,9 @@ CURLcode test(char *URL)
test_setopt(curl, CURLOPT_PROXY, libtest_arg2); test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_HTTPHEADER, hhl); test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
test_setopt(curl, CURLOPT_PROXYHEADER, phl); 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_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_HEADER, 1L);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);

View File

@ -49,7 +49,7 @@ CURLcode test(char *URL)
test_setopt(curl, CURLOPT_URL, bURL); test_setopt(curl, CURLOPT_URL, bURL);
test_setopt(curl, CURLOPT_PROXY, libtest_arg2); test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
test_setopt(curl, CURLOPT_VERBOSE, 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_HEADER, 1L);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);

View File

@ -50,7 +50,7 @@ CURLcode test(char *URL)
test_setopt(curl, CURLOPT_POSTFIELDS, "moo"); test_setopt(curl, CURLOPT_POSTFIELDS, "moo");
} }
if(testno == 1581) { 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"); test_setopt(curl, CURLOPT_CUSTOMREQUEST, "IGLOO");

View File

@ -48,7 +48,7 @@ CURLcode test(char *URL)
CURL *curl = NULL; CURL *curl = NULL;
CURLcode res = CURLE_OK; CURLcode res = CURLE_OK;
CURLMcode mres; CURLMcode mres;
int timeout; long timeout;
global_init(CURL_GLOBAL_ALL); global_init(CURL_GLOBAL_ALL);

View File

@ -133,7 +133,7 @@ CURLcode test(char *URL)
/* use the callback style */ /* use the callback style */
curl_easy_setopt(curl, CURLOPT_USERAGENT, "webbie-sox/3"); curl_easy_setopt(curl, CURLOPT_USERAGENT, "webbie-sox/3");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); 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_WRITEFUNCTION, writecb);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl); curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);

View File

@ -103,7 +103,7 @@ test_thread(void *ptr)
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_callback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr); 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 */ /* Perform the request, res will get the return code */
res = curl_easy_perform(curl); res = curl_easy_perform(curl);

View 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_URL, url);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "CURLOPT_CAINFO_BLOB"); curl_easy_setopt(curl, CURLOPT_USERAGENT, "CURLOPT_CAINFO_BLOB");
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS,
CURLSSLOPT_REVOKE_BEST_EFFORT); (long)CURLSSLOPT_REVOKE_BEST_EFFORT);
blob.data = certdata; blob.data = certdata;
blob.len = certsize; blob.len = certsize;

View File

@ -341,6 +341,7 @@ CURLcode test(char *URL)
curl_mime *mimepost = NULL; curl_mime *mimepost = NULL;
FILE *stream = stderr; FILE *stream = stderr;
struct testdata object; struct testdata object;
CURLU *curlu = (CURLU *)&object;
char *charp; char *charp;
long val; long val;
curl_off_t oval; curl_off_t oval;
@ -495,7 +496,7 @@ MOO
elsif(($name eq "CURLOPT_POSTFIELDS") || elsif(($name eq "CURLOPT_POSTFIELDS") ||
($name eq "CURLOPT_COPYPOSTFIELDS")) { ($name eq "CURLOPT_COPYPOSTFIELDS")) {
# set size to zero to avoid it being "illegal" # 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"; print $fh "${fpref} stringpointerextra);\n$fcheck";
} }
elsif($name eq "CURLOPT_HTTPPOST") { elsif($name eq "CURLOPT_HTTPPOST") {
@ -507,6 +508,9 @@ MOO
elsif($name eq "CURLOPT_STDERR") { elsif($name eq "CURLOPT_STDERR") {
print $fh "${fpref} stream);\n$fcheck"; print $fh "${fpref} stream);\n$fcheck";
} }
elsif($name eq "CURLOPT_CURLU") {
print $fh "${fpref} curlu);\n$fcheck";
}
else { else {
print $fh "${fpref} &object);\n$fcheck"; print $fh "${fpref} &object);\n$fcheck";
} }
@ -595,7 +599,7 @@ MOO
print $fh <<FOOTER print $fh <<FOOTER
) )
/* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) */ /* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) */
curl_easy_setopt(curl, (CURLoption)1, 0); curl_easy_setopt(curl, (CURLoption)1, 0L);
res = CURLE_OK; res = CURLE_OK;
test_cleanup: test_cleanup:
curl_easy_cleanup(curl); curl_easy_cleanup(curl);