]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: port to strict C + valgrind
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 8 Sep 2016 02:49:55 +0000 (19:49 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 8 Sep 2016 02:51:12 +0000 (19:51 -0700)
* 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.

bootstrap.conf
src/sort.c

index 985018f67973bf3a67d557433029dd26d3429204..8a0ff31898ccc471748e24dba5f44861e16e4243 100644 (file)
@@ -88,6 +88,7 @@ gnulib_modules="
   filemode
   filenamecat
   filevercmp
+  flexmember
   fnmatch-gnu
   fopen-safer
   fprintftime
index 079547595af3977fc0292678ee2dd87e3db93487..b30f5d036f6a5e060b2fc648cc956a28d5dfc907 100644 (file)
@@ -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;