+2015-10-18 Paul Eggert <eggert@cs.ucla.edu>
+
+ fts: port to C11 alignof
+ * doc/posix-headers/stdalign.texi (stdalign.h):
+ Document the C11 restriction.
+ * lib/fts.c: Include stddef.h, for max_align_t.
+ (fts_alloc): Align using max_align_t, not FTSENT.
+ * modules/fts (Depends-on): Add stddef.
+
2015-10-18 Jim Meyering <meyering@fb.com>
time_rz: avoid warning from bleeding-edge gcc's -Wnonnull
which the operand can also be a unary expression, as with
@code{sizeof}. The Gnulib substitute does not support this extension.
@item
+In ISO C11, the operand of @code{alignof}/@code{_Alignof} must be a
+complete type. Recent versions of GCC support an extension in which
+the operand can also be structure type containing a flexible array
+member. The Gnulib substitute does not support this extension.
+@item
@code{_Alignas} and @code{alignas} are not always supported;
on platforms lacking support, the
macro @code{__alignas_is_defined} is not defined.
#include <errno.h>
#include <stdalign.h>
#include <stdbool.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
* structure and the file name in one chunk.
*/
len = offsetof(FTSENT, fts_name) + namelen + 1;
- /* Round the allocation up so it has the same alignment as FTSENT,
+ /* Align the allocation size so that it works for FTSENT,
so that trailing padding may be referenced by direct access
to the flexible array members, without triggering undefined behavior
by accessing bytes beyond the heap allocation. This implicit access
- was seen for example with ISDOT() and GCC 5.1.1 at -O2. */
- len = (len + alignof(FTSENT) - 1) & ~(alignof(FTSENT) - 1);
+ was seen for example with ISDOT() and GCC 5.1.1 at -O2.
+ Do not use alignof (FTSENT) here, since C11 prohibits
+ taking the alignment of a structure containing a flexible
+ array member. */
+ len += alignof (max_align_t) - 1;
+ len &= ~ (alignof (max_align_t) - 1);
if ((p = malloc(len)) == NULL)
return (NULL);
readdir
stdalign
stdbool
+stddef
unistd-safer
configure.ac: