diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2015-04-27 01:19:03 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2015-04-27 01:24:40 -0700 |
commit | e4584a9e26ea39e2f961a700c60f3a10ec07dbb4 (patch) | |
tree | b4056aee3400d84f5e4d75b188471c5cbf7fd790 | |
parent | ff714c0a2094bdefd9ed41603493e66aaf285f12 (diff) | |
download | gnulib-e4584a9e26ea39e2f961a700c60f3a10ec07dbb4.tar.gz |
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.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | lib/fts.c | 2 | ||||
-rw-r--r-- | lib/fts_.h | 8 | ||||
-rw-r--r-- | modules/fts | 1 |
4 files changed, 21 insertions, 2 deletions
@@ -1,3 +1,15 @@ +2015-04-27 Paul Eggert <eggert@cs.ucla.edu> + + 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 <eggert@cs.ucla.edu> file-has-acl: port to CentOS 6 @@ -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 <features.h> +# 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 |