From: Daniel Stenberg Date: Fri, 11 Apr 2025 12:40:48 +0000 (+0200) Subject: docs/libcurl: make examples build with picky compiler options X-Git-Tag: curl-8_14_0~319 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=960984263f926fd55494954273987c49ec17572d;p=thirdparty%2Fcurl.git docs/libcurl: make examples build with picky compiler options Found by improving verify-examples.pl: - Operate directly on markdown files to remove the need to render nroff files first. - Add -Wall as a compiler option to find more issues Closes #17028 --- diff --git a/.github/scripts/verify-examples.pl b/.github/scripts/verify-examples.pl index 28d24595ff..1366db0a88 100755 --- a/.github/scripts/verify-examples.pl +++ b/.github/scripts/verify-examples.pl @@ -29,12 +29,12 @@ my $check = "./scripts/checksrc.pl"; my $error; if($files[0] eq "-h") { - print "Usage: verify-synopsis [man pages]\n"; + print "Usage: verify-examples [markdown pages]\n"; exit; } sub testcompile { - my $rc = system("gcc -c test.c -DCURL_DISABLE_TYPECHECK -DCURL_ALLOW_OLD_MULTI_SOCKET -DCURL_DISABLE_DEPRECATION -Wunused -Werror -Wno-unused-but-set-variable -I include") >> 8; + my $rc = system("gcc -c test.c -DCURL_DISABLE_TYPECHECK -DCURL_ALLOW_OLD_MULTI_SOCKET -DCURL_DISABLE_DEPRECATION -Wunused -Werror -Wall -Wno-unused-but-set-variable -I include") >> 8; return $rc; } @@ -54,11 +54,11 @@ sub extract { print O "#include \n"; while() { $iline++; - if(/^.SH EXAMPLE/) { + if(/^# EXAMPLE/) { $syn = 1 } elsif($syn == 1) { - if(/^.nf/) { + if(/^~~~/) { $syn++; print O "/* !checksrc! disable UNUSEDIGNORE all */\n"; print O "/* !checksrc! disable COPYRIGHT all */\n"; @@ -67,16 +67,7 @@ sub extract { } } elsif($syn == 2) { - if(/^.fi/) { - last; - } - if(/(?easy); printf("flags: %x\n", m->flags); + return 0; } int main(void) @@ -158,6 +159,7 @@ int main(void) curl_easy_perform(curl); } + return 0; } ~~~ diff --git a/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md b/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md index 35c1ae0c1c..41b8125b41 100644 --- a/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md +++ b/docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md @@ -63,7 +63,7 @@ NULL int main(void) { - char *strpem; /* strpem must point to a PEM string */ + char *strpem = "PEMDATA"; /* strpem must point to a PEM string */ CURL *curl = curl_easy_init(); if(curl) { CURLcode res; diff --git a/docs/libcurl/opts/CURLOPT_DEBUGDATA.md b/docs/libcurl/opts/CURLOPT_DEBUGDATA.md index 4fc336667e..ed84a27d12 100644 --- a/docs/libcurl/opts/CURLOPT_DEBUGDATA.md +++ b/docs/libcurl/opts/CURLOPT_DEBUGDATA.md @@ -51,6 +51,7 @@ static int my_trace(CURL *handle, curl_infotype type, printf("our ptr: %p\n", mine->custom); /* output debug info */ + return 0; } int main(void) diff --git a/docs/libcurl/opts/CURLOPT_POSTFIELDSIZE_LARGE.md b/docs/libcurl/opts/CURLOPT_POSTFIELDSIZE_LARGE.md index 2032fbc517..16e874b667 100644 --- a/docs/libcurl/opts/CURLOPT_POSTFIELDSIZE_LARGE.md +++ b/docs/libcurl/opts/CURLOPT_POSTFIELDSIZE_LARGE.md @@ -50,7 +50,7 @@ int main(void) CURL *curl = curl_easy_init(); if(curl) { const char *data = large_chunk; - curl_off_t length_of_data; /* set somehow */ + curl_off_t length_of_data = 12345; /* set somehow */ curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); diff --git a/docs/libcurl/opts/CURLOPT_PUT.md b/docs/libcurl/opts/CURLOPT_PUT.md index ae064979c3..870cc9a460 100644 --- a/docs/libcurl/opts/CURLOPT_PUT.md +++ b/docs/libcurl/opts/CURLOPT_PUT.md @@ -58,7 +58,7 @@ int main(void) CURL *curl = curl_easy_init(); if(curl) { FILE *src = fopen("local-file", "r"); - curl_off_t fsize; /* set this to the size of the input file */ + curl_off_t fsize = 123456; /* set this to the size of the input file */ /* we want to use our own read function */ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb); diff --git a/docs/libcurl/opts/CURLOPT_RESUME_FROM.md b/docs/libcurl/opts/CURLOPT_RESUME_FROM.md index f3c8faf726..73892b1030 100644 --- a/docs/libcurl/opts/CURLOPT_RESUME_FROM.md +++ b/docs/libcurl/opts/CURLOPT_RESUME_FROM.md @@ -53,7 +53,7 @@ int main(void) { CURL *curl = curl_easy_init(); if(curl) { - long size_of_file; + long size_of_file = 6789; curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com"); diff --git a/docs/libcurl/opts/CURLOPT_RESUME_FROM_LARGE.md b/docs/libcurl/opts/CURLOPT_RESUME_FROM_LARGE.md index a658bba8bd..32bc341af5 100644 --- a/docs/libcurl/opts/CURLOPT_RESUME_FROM_LARGE.md +++ b/docs/libcurl/opts/CURLOPT_RESUME_FROM_LARGE.md @@ -51,8 +51,8 @@ int main(void) { CURL *curl = curl_easy_init(); if(curl) { - curl_off_t resume_position; /* get it somehow */ - curl_off_t file_size; /* get it somehow as well */ + curl_off_t resume_position = 1234; /* get it somehow */ + curl_off_t file_size = 9876; /* get it somehow as well */ curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com"); diff --git a/docs/libcurl/opts/CURLOPT_RTSP_SESSION_ID.md b/docs/libcurl/opts/CURLOPT_RTSP_SESSION_ID.md index 1724b9a8ce..0d76e60186 100644 --- a/docs/libcurl/opts/CURLOPT_RTSP_SESSION_ID.md +++ b/docs/libcurl/opts/CURLOPT_RTSP_SESSION_ID.md @@ -53,7 +53,7 @@ int main(void) CURL *curl = curl_easy_init(); if(curl) { CURLcode res; - char *prev_id; /* saved from before somehow */ + char *prev_id = "old"; /* saved from before somehow */ curl_easy_setopt(curl, CURLOPT_URL, "rtsp://example.com/"); curl_easy_setopt(curl, CURLOPT_RTSP_SESSION_ID, prev_id); res = curl_easy_perform(curl); diff --git a/docs/libcurl/opts/CURLOPT_UPLOAD.md b/docs/libcurl/opts/CURLOPT_UPLOAD.md index c1189e24e9..a396a0eca1 100644 --- a/docs/libcurl/opts/CURLOPT_UPLOAD.md +++ b/docs/libcurl/opts/CURLOPT_UPLOAD.md @@ -66,7 +66,7 @@ int main(void) CURL *curl = curl_easy_init(); if(curl) { FILE *src = fopen("local-file", "r"); - curl_off_t fsize; /* set this to the size of the input file */ + curl_off_t fsize = 1234; /* set this to the size of the input file */ /* we want to use our own read function */ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb); diff --git a/docs/libcurl/opts/CURLOPT_UPLOAD_FLAGS.md b/docs/libcurl/opts/CURLOPT_UPLOAD_FLAGS.md index 06b53f32ff..4c650186bf 100644 --- a/docs/libcurl/opts/CURLOPT_UPLOAD_FLAGS.md +++ b/docs/libcurl/opts/CURLOPT_UPLOAD_FLAGS.md @@ -58,7 +58,7 @@ int main(void) CURL *curl = curl_easy_init(); if(curl) { FILE *src = fopen("local-file", "r"); - curl_off_t fsize; /* set this to the size of the input file */ + curl_off_t fsize = 9876; /* set this to the size of the input file */ /* we want to use our own read function */ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);