]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: follow-up to fix categories in --help
authorDan Fandrich <dan@coneharvesters.com>
Fri, 28 Jun 2024 21:41:29 +0000 (14:41 -0700)
committerDan Fandrich <dan@coneharvesters.com>
Fri, 5 Jul 2024 21:44:43 +0000 (14:44 -0700)
The commit 6483813b was missing changes necessitated by 2abfc75 that
causes a crash. Also, use ARRAYSIZE() for cleaner code.

Follow-up to 6483813b

Ref #14055

src/tool_help.c
tests/data/test1461

index a3df3b14b6ac5fadbdf862c2c6f6ae1a307d7f92..a12626eff3ea3a64799c0914dff45aca7c1de35f 100644 (file)
 #  define USE_WATT32
 #endif
 
+#ifndef ARRAYSIZE
+#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
+#endif
+
 struct category_descriptors {
   const char *opt;
   const char *desc;
@@ -112,7 +116,7 @@ static void print_category(unsigned int category, unsigned int cols)
 static int get_category_content(const char *category, unsigned int cols)
 {
   unsigned int i;
-  for(i = 0; i < sizeof(categories)/sizeof(categories[0]); ++i)
+  for(i = 0; i < ARRAYSIZE(categories); ++i)
     if(curl_strequal(categories[i].opt, category)) {
       printf("%s: %s\n", categories[i].opt, categories[i].desc);
       print_category(categories[i].category, cols);
@@ -125,7 +129,7 @@ static int get_category_content(const char *category, unsigned int cols)
 static void get_categories(void)
 {
   unsigned int i;
-  for(i = 0; i < sizeof(categories)/sizeof(categories[0]); ++i)
+  for(i = 0; i < ARRAYSIZE(categories); ++i)
     printf(" %-11s %s\n", categories[i].opt, categories[i].desc);
 }
 
@@ -134,9 +138,9 @@ static void get_categories_list(unsigned int width)
 {
   unsigned int i;
   size_t col = 0;
-  for(i = 0; categories[i].opt; ++i) {
+  for(i = 0; i < ARRAYSIZE(categories); ++i) {
     size_t len = strlen(categories[i].opt);
-    if(!categories[i + 1].opt) {
+    if(i == ARRAYSIZE(categories) - 1) {
       /* final category */
       if(col + len + 1 < width)
         printf("%s.\n", categories[i].opt);
index e9a93b5a979a8bc342288b319ab9acacd1f25b73..669e5fbf45cfafbb51149ba39df9da43bd903986 100644 (file)
@@ -47,8 +47,9 @@ Usage: curl [options...] <url>
 
 This is not the full help; this menu is split into categories.
 Use "--help category" to get an overview of all categories, which are:
-auth, connection, curl, dns, file, ftp, http, imap, misc, output, pop3, post, 
-proxy, scp, sftp, smtp, ssh, telnet, tftp, tls, ech, upload, verbose.
+auth, connection, curl, deprecated, dns, file, ftp, global, http, imap, ldap, 
+output, pop3, post, proxy, scp, sftp, smtp, ssh, telnet, tftp, timeout, tls, 
+upload, verbose.
 For all options use the manual or "--help all".
 </stdout>
 </verify>