Port to strict C99 struct hack

Portability bug caught by GCC 13 -fstrict-flex-arrays.
* gnulib.modules: Add flexmember.
* src/create.c (struct link):
* src/exclist.c (struct excfile):
* src/extract.c (struct delayed_link, struct string_list):
Include <flexmember.h>.  Use FLEXIBLE_ARRAY_MEMBER, for
portability to strict C99 or later.  All storage
allocations changed to use FLEXNSIZEOF.
This commit is contained in:
Paul Eggert
2023-06-16 17:12:40 -07:00
parent 4c7a3798d8
commit c542d3d0c8
4 changed files with 17 additions and 12 deletions
+3 -3
View File
@@ -22,6 +22,7 @@
#include <system.h>
#include <areadlink.h>
#include <flexmember.h>
#include <quotearg.h>
#include "common.h"
@@ -36,7 +37,7 @@ struct link
dev_t dev;
ino_t ino;
nlink_t nlink;
char name[1];
char name[FLEXIBLE_ARRAY_MEMBER];
};
struct exclusion_tag
@@ -1518,8 +1519,7 @@ file_count_links (struct tar_stat_info *st)
absolute_names_option));
transform_name (&linkname, XFORM_LINK);
lp = xmalloc (offsetof (struct link, name)
+ strlen (linkname) + 1);
lp = xmalloc (FLEXNSIZEOF (struct link, name, strlen (linkname) + 1));
lp->ino = st->stat.st_ino;
lp->dev = st->stat.st_dev;
lp->nlink = st->stat.st_nlink;