bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] fts: port to GCC 5.1 with --enable-gcc-warnings


From: Paul Eggert
Subject: [PATCH 1/2] fts: port to GCC 5.1 with --enable-gcc-warnings
Date: Mon, 27 Apr 2015 01:25:00 -0700

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.
---
 ChangeLog   | 12 ++++++++++++
 lib/fts.c   |  2 +-
 lib/fts_.h  |  8 +++++++-
 modules/fts |  1 +
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0c87783..350553a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2015-04-27  Paul Eggert  <address@hidden>
+
+       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  <address@hidden>
 
        file-has-acl: port to CentOS 6
diff --git a/lib/fts.c b/lib/fts.c
index 352ee05..6084101 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 bbf6484..b9a3f12 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 59e557a..3316264 100644
--- a/modules/fts
+++ b/modules/fts
@@ -19,6 +19,7 @@ fchdir
 fcntl-h
 fcntl-safer
 fdopendir
+flexmember
 fstat
 hash
 i-ring
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]