]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Use flexible array member in struct dumpdir
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 26 Jul 2025 07:47:48 +0000 (00:47 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 26 Jul 2025 09:20:53 +0000 (02:20 -0700)
* src/incremen.c: Include flexmember.h.
(struct dumpdir): contents is now a flexible member, not a pointer.
This is more idiomatic and slightly more efficient.
(dumpdir_create0): Adjust to the new struct dumpdir layout.

src/incremen.c

index 0e4188938193b1d9eff454b019af34913f0fbf4b..020fa1f0a668dd9cae812b1eb40b808a1acc5a18 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <system.h>
 #include <c-ctype.h>
+#include <flexmember.h>
 #include <hash.h>
 #include <quotearg.h>
 #include "common.h"
@@ -61,10 +62,10 @@ enum
 
 struct dumpdir                 /* Dump directory listing */
 {
-  char *contents;              /* Actual contents */
   idx_t total;                /* Total number of elements */
   idx_t elc;                  /* Number of D/N/Y elements. */
   char **elv;                  /* Array of D/N/Y elements */
+  char contents[FLEXIBLE_ARRAY_MEMBER]; /* Actual contents */
 };
 
 /* Directory attributes.  */
@@ -141,8 +142,7 @@ dumpdir_create0 (const char *contents, const char *cmask)
       if (!cmask || strchr (cmask, *q))
        i++;
     }
-  dump = xmalloc (sizeof (*dump) + ctsize);
-  dump->contents = (char *) (dump + 1);
+  dump = xmalloc (FLEXNSIZEOF (struct dumpdir, contents, ctsize));
   memcpy (dump->contents, contents, ctsize);
   dump->total = total;
   dump->elc = i;