aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorPaul Eggert2016-09-07 18:08:45 -0700
committerPaul Eggert2016-09-07 18:10:11 -0700
commitd2f1971dd570439da4198fa76603b53b072060f8 (patch)
tree38b1ddbeda27b6ed6ac52205169624608cc597fd /src/process.c
parent12a7e0f88eaa68aabe7e32589e2d5c8f776f6346 (diff)
downloademacs-d2f1971dd570439da4198fa76603b53b072060f8.tar.gz
emacs-d2f1971dd570439da4198fa76603b53b072060f8.zip
Port flexible array members to GCC + valgrind
These changes are needed to conform to the C standard's rule for allocating structs containing flexible array members. C11 says that malloc (offsetof (struct s, m) + n) does not suffice to allocate a struct with an n-byte tail; instead, malloc’s arg should be rounded up to the nearest multiple of alignof (struct s). Although this is arguably a defect in C11, gcc -O2 + valgrind sometimes complains when this rule is violated, and when debugging it’s better to keep valgrind happy. For details please see the thread containing the message at: https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00416.html * lib-src/ebrowse.c, src/alloc.c, src/image.c, src/process.c: Include flexmember.h. * lib-src/ebrowse.c (add_sym, add_member, make_namespace) (register_namespace_alias): * src/alloc.c (SDATA_SIZE, allocate_string_data): * src/image.c (xpm_cache_color, imagemagick_create_cache): * src/process.c (Fmake_network_process): Use FLEXSIZEOF instead of offsetof and addition. * src/alloc.c (SDATA_SIZE, vector_alignment): Use FLEXALIGNOF instead of sizeof (ptrdiff_t). * src/lisp.h (ALIGNOF_STRUCT_LISP_VECTOR): Remove, as alloc.c can now calculate this on its own.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/process.c b/src/process.c
index 989511967ce..29bf43e0f29 100644
--- a/src/process.c
+++ b/src/process.c
@@ -88,6 +88,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
88#endif 88#endif
89 89
90#include <c-ctype.h> 90#include <c-ctype.h>
91#include <flexmember.h>
91#include <sig2str.h> 92#include <sig2str.h>
92#include <verify.h> 93#include <verify.h>
93 94
@@ -3807,8 +3808,8 @@ usage: (make-network-process &rest ARGS) */)
3807 struct gaicb gaicb; 3808 struct gaicb gaicb;
3808 struct addrinfo hints; 3809 struct addrinfo hints;
3809 char str[FLEXIBLE_ARRAY_MEMBER]; 3810 char str[FLEXIBLE_ARRAY_MEMBER];
3810 } *req = xmalloc (offsetof (struct req, str) 3811 } *req = xmalloc (FLEXSIZEOF (struct req, str,
3811 + hostlen + 1 + portstringlen + 1); 3812 hostlen + 1 + portstringlen + 1));
3812 dns_request = &req->gaicb; 3813 dns_request = &req->gaicb;
3813 dns_request->ar_name = req->str; 3814 dns_request->ar_name = req->str;
3814 dns_request->ar_service = req->str + hostlen + 1; 3815 dns_request->ar_service = req->str + hostlen + 1;