]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
docs/libcurl: make examples build with picky compiler options
authorDaniel Stenberg <daniel@haxx.se>
Fri, 11 Apr 2025 12:40:48 +0000 (14:40 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 11 Apr 2025 13:23:51 +0000 (15:23 +0200)
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

24 files changed:
.github/scripts/verify-examples.pl
.github/workflows/checkdocs.yml
docs/libcurl/curl_easy_ssls_import.md
docs/libcurl/curl_multi_assign.md
docs/libcurl/curl_multi_poll.md
docs/libcurl/curl_multi_setopt.md
docs/libcurl/curl_multi_socket.md
docs/libcurl/curl_multi_socket_action.md
docs/libcurl/curl_multi_socket_all.md
docs/libcurl/curl_multi_timeout.md
docs/libcurl/curl_multi_wait.md
docs/libcurl/curl_multi_wakeup.md
docs/libcurl/curl_slist_append.md
docs/libcurl/curl_slist_free_all.md
docs/libcurl/curl_ws_meta.md
docs/libcurl/opts/CURLOPT_CAINFO_BLOB.md
docs/libcurl/opts/CURLOPT_DEBUGDATA.md
docs/libcurl/opts/CURLOPT_POSTFIELDSIZE_LARGE.md
docs/libcurl/opts/CURLOPT_PUT.md
docs/libcurl/opts/CURLOPT_RESUME_FROM.md
docs/libcurl/opts/CURLOPT_RESUME_FROM_LARGE.md
docs/libcurl/opts/CURLOPT_RTSP_SESSION_ID.md
docs/libcurl/opts/CURLOPT_UPLOAD.md
docs/libcurl/opts/CURLOPT_UPLOAD_FLAGS.md

index 28d24595fff9033e65391c4ebb68bdab2ceb35bd..1366db0a880c43bae4b58be873a68f2cac2cda4d 100755 (executable)
@@ -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 <curl/curl.h>\n";
     while(<F>) {
         $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(/(?<!\\)(?:\\{2})*\\(?!\\)/) {
-                print STDERR
-                  "Error while processing file $f line $iline:\n$_" .
-                  "Error: Single backslashes \\ are not properly shown in " .
-                  "manpage EXAMPLE output unless they are escaped \\\\.\n";
-                $fail = 1;
-                $error = 1;
+            if(/^~~~/) {
                 last;
             }
             # two backslashes become one
index 03f61a04a8e901995a9f92ad8a6c561f9bebe43b..fd92c814ac55cca70d44485c5e7df17792c3fc8e 100644 (file)
@@ -140,11 +140,8 @@ jobs:
           persist-credentials: false
         name: checkout
 
-      - name: render nroff versions
-        run: autoreconf -fi && ./configure --without-ssl --without-libpsl && make -C docs
-
       - name: verify examples
-        run: .github/scripts/verify-examples.pl docs/libcurl/curl*.3 docs/libcurl/opts/*.3
+        run: .github/scripts/verify-examples.pl docs/libcurl/curl*.md docs/libcurl/opts/*.md
 
   miscchecks:
     runs-on: ubuntu-24.04-arm
index 13653ae9e2cfaa829fe73725bc025a30a177f5b2..1c490ccc93a7f19b0f24059fb881b47984d69723 100644 (file)
@@ -63,8 +63,8 @@ int main(void)
 
   curl = curl_easy_init();
   if(curl) {
-    unsigned char *shmac, *sdata;
-    size_t hlen, slen;
+    extern unsigned char *shmac, *sdata;
+    size_t hlen = 4, slen = 5;
 
     curl_easy_setopt(curl, CURLOPT_SHARE, share);
 
index eb4fb966e5085a38c5e293338aa754134f9a9c07..36579fd9f83b8375202df09801a338bb59113983 100644 (file)
@@ -56,11 +56,11 @@ It is acceptable to call this function from your multi callback functions.
 int main(void)
 {
   CURLM *multi = curl_multi_init();
-  void *ourstructp; /* pointer to our data */
-  curl_socket_t fd; /* file descriptor to associate our data with */
+  int private = 123;
+  curl_socket_t fd = 0; /* file descriptor to associate our data with */
 
   /* make our struct pointer associated with socket fd */
-  CURLMcode mc = curl_multi_assign(multi, fd, ourstructp);
+  CURLMcode mc = curl_multi_assign(multi, fd, &private);
   if(mc)
     printf("error: %s\n", curl_multi_strerror(mc));
 }
index 4cfc98520e68a361a19dfdb975e74977014b2fd6..64aeac9d10f2a02a4588b34d6fa8a8f0210e3ce3 100644 (file)
@@ -99,7 +99,10 @@ int main(void)
   CURL *easy_handle;
   CURLM *multi_handle;
   int still_running = 0;
-  int myfd; /* this is our own file descriptor */
+  int myfd = 2; /* this is our own file descriptor */
+
+  multi_handle = curl_multi_init();
+  easy_handle = curl_easy_init();
 
   /* add the individual easy handle */
   curl_multi_add_handle(multi_handle, easy_handle);
index 70e7528821171a7f1a3e06920214d8cedc801fbf..55cc11beac2e6c090abbb9afa83bbcb6f31cb690 100644 (file)
@@ -114,7 +114,8 @@ Callback to receive timeout values. See CURLMOPT_TIMERFUNCTION(3)
 
 int main(void)
 {
-  CURLM *multi;
+  CURLM *multi = curl_multi_init();
+
   /* Limit the amount of simultaneous connections curl should allow: */
   curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);
 }
index 1f20b51ab075e0bcd93bb0e05d9313f0b369c735..f77bba85920e7b44150f4265150d52175abd1d6d 100644 (file)
@@ -65,8 +65,9 @@ int main(void)
      which we translate to a call to curl_multi_socket_action() */
   int running;
   int rc;
-  int fd;
-  CURLM *multi;
+  int fd = 2;
+  CURLM *multi = curl_multi_init();
+
   rc = curl_multi_socket(multi, fd, &running);
 }
 ~~~
index 0b5889a7debdc002ac8aa9f7afd132702d081349..5d4271a38689243a59a1f89080bbd769066737de 100644 (file)
@@ -105,10 +105,12 @@ int main(void)
 {
   /* the event-library gets told when there activity on the socket 'fd',
      which we translate to a call to curl_multi_socket_action() */
-  int running;
-  CURLM *multi; /* the stack we work with */
-  int fd; /* the descriptor that had action */
-  int bitmask; /* what activity that happened */
+  int running = 0;
+  int fd = 3; /* the descriptor that had action */
+  int bitmask = 2; /* what activity that happened */
+
+  CURLM *multi = curl_multi_init();
+
   CURLMcode mc = curl_multi_socket_action(multi, fd, bitmask, &running);
   if(mc)
     printf("error: %s\n", curl_multi_strerror(mc));
index d0806ba5663f695acbe9ac6b6459e6254a428fe1..5428b9786be5ca4adb5380b9da482904630e80c3 100644 (file)
@@ -50,7 +50,8 @@ int main(void)
 {
   int running;
   int rc;
-  CURLM *multi;
+  CURLM *multi = curl_multi_init();
+
   rc = curl_multi_socket_all(multi, &running);
 }
 ~~~
index 05121237c125507f1bc4ce3a2f209bc2610d723a..273ab795387029af01ac2fd683f0ee1999efd85b 100644 (file)
@@ -61,7 +61,7 @@ int main(void)
   fd_set fdread;
   fd_set fdwrite;
   fd_set fdexcep;
-  int maxfd;
+  int maxfd = 2;
   CURLM *multi = curl_multi_init();
 
   curl_multi_timeout(multi, &timeo);
index d73cf0e0be2eedbf3eb9f2709b07346b51daa60b..b8f5a18e6746fcea65e7cee4a82e24b1234f3671 100644 (file)
@@ -91,6 +91,8 @@ int main(void)
   CURLM *multi = curl_multi_init();
   int still_running;
 
+  easy = curl_easy_init();
+
   /* add the individual easy handle */
   curl_multi_add_handle(multi, easy);
 
index 6e6ca1a5c687ccd7d1585b2fadc46c950256353a..78597bf88f34f8c32324de99d87aa1601c5e1a9e 100644 (file)
@@ -51,9 +51,11 @@ extern int decide_to_stop_thread1();
 int main(void)
 {
   CURL *easy;
-  CURLM *multi;
+  CURLM *multi = curl_multi_init();
   int still_running;
 
+  easy = curl_easy_init();
+
   /* add the individual easy handle */
   curl_multi_add_handle(multi, easy);
 
index 27ec45da1c40e1bb5c535b431227cde532eb4419..75c6a57afd508eaa8a37ef368c359fcfae3bb3bc 100644 (file)
@@ -42,7 +42,7 @@ curl_slist_free_all(3).
 ~~~c
 int main(void)
 {
-  CURL *handle;
+  CURL *handle = curl_easy_init();
   struct curl_slist *slist = NULL;
   struct curl_slist *temp = NULL;
 
index 91491aa6c0a7fea213f71e57e0fe2df200f85bd1..d3e5e04a95943efbcd46d65cd8f2ebba93b28c94 100644 (file)
@@ -41,7 +41,7 @@ is illegal.
 ~~~c
 int main(void)
 {
-  CURL *handle;
+  CURL *handle = curl_easy_init();
   struct curl_slist *slist = NULL;
 
   slist = curl_slist_append(slist, "X-libcurl: coolness");
index 95505b0bdae57232e59e2a10c4a6d759cfadb72b..ed9e154722863efce711ccc3373aee46e2b39615 100644 (file)
@@ -143,6 +143,7 @@ static size_t writecb(unsigned char *buffer,
   const struct curl_ws_frame *m = curl_ws_meta(c->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;
 }
 ~~~
 
index 35c1ae0c1cdc3643600be02d6e4c1cd871970cec..41b8125b419a022c5d9f6b8e9106c24534dae0ce 100644 (file)
@@ -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;
index 4fc336667e8f2bf0843d54ff76d9229e69bae280..ed84a27d1235528590d2f900b3240f2445b2c584 100644 (file)
@@ -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)
index 2032fbc517b2b3230eb50e6cfa7254b29d40aec3..16e874b667ed80278d7019931dd0d48b1f8f52eb 100644 (file)
@@ -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");
 
index ae064979c3508061ab5ade23082b8f7b064d9a5d..870cc9a460b011b4aa4d05009c4793f4cbb0ff57 100644 (file)
@@ -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);
index f3c8faf726655d5f99827fba7de85d61a7cd38f5..73892b10301a2b8b72e8a05d686b36f332c7d596 100644 (file)
@@ -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");
 
index a658bba8bd1da61797aa4367eab67f22c8079a64..32bc341af5c4e7ff717d2427dbe9bc8b00d74ee4 100644 (file)
@@ -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");
 
index 1724b9a8ce9c55b695e325ef3ce7948e2bc7324f..0d76e60186b0d2f8f77d8c256cdf82431d0b298c 100644 (file)
@@ -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);
index c1189e24e9ef158429459b302fe575bfb85101c5..a396a0eca16551eb77577501880ee81ed9f48b5b 100644 (file)
@@ -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);
index 06b53f32ff217ea179e7f5acc22376a7877368fe..4c650186bf50a095aee183e649e8446ccc2b3999 100644 (file)
@@ -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);