aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2016-09-07 18:08:45 -0700
committerPaul Eggert2016-09-07 18:10:11 -0700
commitd2f1971dd570439da4198fa76603b53b072060f8 (patch)
tree38b1ddbeda27b6ed6ac52205169624608cc597fd /lib-src
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 'lib-src')
-rw-r--r--lib-src/ebrowse.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c
index c59181f9464..7a262005df9 100644
--- a/lib-src/ebrowse.c
+++ b/lib-src/ebrowse.c
@@ -32,6 +32,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
32#define SEEK_END 2 32#define SEEK_END 2
33#endif 33#endif
34 34
35#include <flexmember.h>
35#include <min-max.h> 36#include <min-max.h>
36 37
37/* Files are read in chunks of this number of bytes. */ 38/* Files are read in chunks of this number of bytes. */
@@ -582,7 +583,7 @@ add_sym (const char *name, struct sym *nested_in_class)
582 puts (name); 583 puts (name);
583 } 584 }
584 585
585 sym = xmalloc (offsetof (struct sym, name) + strlen (name) + 1); 586 sym = xmalloc (FLEXSIZEOF (struct sym, name, strlen (name) + 1));
586 memset (sym, 0, offsetof (struct sym, name)); 587 memset (sym, 0, offsetof (struct sym, name));
587 strcpy (sym->name, name); 588 strcpy (sym->name, name);
588 sym->namesp = scope; 589 sym->namesp = scope;
@@ -867,8 +868,8 @@ add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var,
867static struct member * 868static struct member *
868add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash) 869add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
869{ 870{
870 struct member *m = xmalloc (offsetof (struct member, name) 871 struct member *m = xmalloc (FLEXSIZEOF (struct member, name,
871 + strlen (name) + 1); 872 strlen (name) + 1));
872 struct member **list; 873 struct member **list;
873 struct member *p; 874 struct member *p;
874 struct member *prev; 875 struct member *prev;
@@ -978,7 +979,7 @@ mark_inherited_virtual (void)
978static struct sym * 979static struct sym *
979make_namespace (char *name, struct sym *context) 980make_namespace (char *name, struct sym *context)
980{ 981{
981 struct sym *s = xmalloc (offsetof (struct sym, name) + strlen (name) + 1); 982 struct sym *s = xmalloc (FLEXSIZEOF (struct sym, name, strlen (name) + 1));
982 memset (s, 0, offsetof (struct sym, name)); 983 memset (s, 0, offsetof (struct sym, name));
983 strcpy (s->name, name); 984 strcpy (s->name, name);
984 s->next = all_namespaces; 985 s->next = all_namespaces;
@@ -1062,7 +1063,7 @@ register_namespace_alias (char *new_name, struct link *old_name)
1062 if (streq (new_name, al->name) && (al->namesp == current_namespace)) 1063 if (streq (new_name, al->name) && (al->namesp == current_namespace))
1063 return; 1064 return;
1064 1065
1065 al = xmalloc (offsetof (struct alias, name) + strlen (new_name) + 1); 1066 al = xmalloc (FLEXSIZEOF (struct alias, name, strlen (new_name) + 1));
1066 strcpy (al->name, new_name); 1067 strcpy (al->name, new_name);
1067 al->next = namespace_alias_table[h]; 1068 al->next = namespace_alias_table[h];
1068 al->namesp = current_namespace; 1069 al->namesp = current_namespace;