From: Paul Eggert Date: Mon, 27 Apr 2015 08:19:03 +0000 (-0700) Subject: fts: port to GCC 5.1 with --enable-gcc-warnings X-Git-Tag: v1.0~7084 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=e4584a9e26ea39e2f961a700c60f3a10ec07dbb4;p=gnulib.git fts: port to GCC 5.1 with --enable-gcc-warnings Without this fix, GCC 5.1 (correctly) warns about a subscript error on the fts_name component of FTSENT. It's actually a flexible member, so define it that way on C99 or later hosts. * lib/fts.c (fts_alloc): Use offsetof, not sizeof, for a structure that now has a flexible array member. * lib/fts_.h (__FLEXIBLE_ARRAY_MEMBER): New macro. (FTSENT): fts_name is now flexible on C99-or-later platforms. * modules/fts (Depends-on): Add flexmember. --- diff --git a/ChangeLog b/ChangeLog index 0c87783608..350553a3c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2015-04-27 Paul Eggert + + fts: port to GCC 5.1 with --enable-gcc-warnings + Without this fix, GCC 5.1 (correctly) warns about a subscript + error on the fts_name component of FTSENT. It's actually a + flexible member, so define it that way on C99 or later hosts. + * lib/fts.c (fts_alloc): Use offsetof, not sizeof, for a + structure that now has a flexible array member. + * lib/fts_.h (__FLEXIBLE_ARRAY_MEMBER): New macro. + (FTSENT): fts_name is now flexible on C99-or-later platforms. + * modules/fts (Depends-on): Add flexmember. + 2015-04-26 Paul Eggert file-has-acl: port to CentOS 6 diff --git a/lib/fts.c b/lib/fts.c index 352ee05744..6084101477 100644 --- a/lib/fts.c +++ b/lib/fts.c @@ -1905,7 +1905,7 @@ fts_alloc (FTS *sp, const char *name, register size_t namelen) * The file name is a variable length array. Allocate the FTSENT * structure and the file name in one chunk. */ - len = sizeof(FTSENT) + namelen; + len = offsetof(FTSENT, fts_name) + namelen + 1; if ((p = malloc(len)) == NULL) return (NULL); diff --git a/lib/fts_.h b/lib/fts_.h index bbf64842e4..b9a3f12cca 100644 --- a/lib/fts_.h +++ b/lib/fts_.h @@ -51,7 +51,13 @@ # ifdef _LIBC # include +# if __STDC_VERSION__ < 199901L +# define __FLEXIBLE_ARRAY_MEMBER 1 +# else +# define __FLEXIBLE_ARRAY_MEMBER +# endif # else +# define __FLEXIBLE_ARRAY_MEMBER FLEXIBLE_ARRAY_MEMBER # undef __THROW # define __THROW # undef __BEGIN_DECLS @@ -243,7 +249,7 @@ typedef struct _ftsent { unsigned short int fts_instr; /* fts_set() instructions */ struct stat fts_statp[1]; /* stat(2) information */ - char fts_name[1]; /* file name */ + char fts_name[__FLEXIBLE_ARRAY_MEMBER]; /* file name */ } FTSENT; #ifndef __GNUC_PREREQ diff --git a/modules/fts b/modules/fts index 59e557a5bd..3316264d03 100644 --- a/modules/fts +++ b/modules/fts @@ -19,6 +19,7 @@ fchdir fcntl-h fcntl-safer fdopendir +flexmember fstat hash i-ring