summaryrefslogtreecommitdiff
path: root/src/sort.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-09-07 19:49:55 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2016-09-07 19:51:12 -0700
commitd47090d964d31bb4af9872525275372efd3bfdce (patch)
tree498db20099df7ce0583581fbfa96e9b817a1224b /src/sort.c
parente9e7289210facb7b541a06d9e12b5364300c76ab (diff)
downloadcoreutils-d47090d964d31bb4af9872525275372efd3bfdce.tar.xz
sort: port to strict C + valgrind
* bootstrap.conf (gnulib_modules): Add flexmember. * src/sort.c: Include flexmember.h. (struct tempnode): Make the last member flexible. (create_temp_file): Port to strict C11/C99 rules for allocation alignment with flexible array members.
Diffstat (limited to 'src/sort.c')
-rw-r--r--src/sort.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/sort.c b/src/sort.c
index 079547595..b30f5d036 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -34,6 +34,7 @@
#include "error.h"
#include "fadvise.h"
#include "filevercmp.h"
+#include "flexmember.h"
#include "hard-locale.h"
#include "hash.h"
#include "heap.h"
@@ -667,7 +668,7 @@ struct tempnode
struct tempnode *volatile next;
pid_t pid; /* The subprocess PID; undefined if state == UNCOMPRESSED. */
char state;
- char name[1]; /* Actual size is 1 + file name length. */
+ char name[FLEXIBLE_ARRAY_MEMBER];
};
static struct tempnode *volatile temphead;
static struct tempnode *volatile *temptail = &temphead;
@@ -855,7 +856,7 @@ create_temp_file (int *pfd, bool survive_fd_exhaustion)
char const *temp_dir = temp_dirs[temp_dir_index];
size_t len = strlen (temp_dir);
struct tempnode *node =
- xmalloc (offsetof (struct tempnode, name) + len + sizeof slashbase);
+ xmalloc (FLEXSIZEOF (struct tempnode, name, len + sizeof slashbase));
char *file = node->name;
struct cs_status cs;