summaryrefslogtreecommitdiff
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2013-06-21 13:11:44 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2013-06-21 13:11:44 -0700
commitfbe9e0b9fb6a250674e7619e9ba794e74ff5f0bc (patch)
tree7b1836faca02f39413afec531c2ae467898523f5 /lib-src
parentcad5d1cb5af7210154814b60825576d14740158f (diff)
downloademacs-fbe9e0b9fb6a250674e7619e9ba794e74ff5f0bc.tar.gz
Use C99-style flexible array members if available.
This avoids some subtle aliasing issues, which typically aren't a problem with GCC but may be a problem elsewhere. * lib-src/ebrowse.c (struct member, struct alias, struct sym): Use FLEXIBLE_ARRAY_MEMBER. (add_sym, add_member, make_namespace, register_namespace_alias): Use offsetof (struct, flex_array_member), not sizeof (struct), as that ports better to pre-C99 non-GCC. * src/alloc.c (sdata): New typedef, replacing the old struct sdata. It is a struct if GC_CHECK_STRING_BYTES, a union otherwise. In either case, it uses a flexible array member rather than the old struct hack. All uses changed. (SDATA_NBYTES, sweep_strings) [!GC_CHECK_STRING_BYTES]: Adjust to sdata reorganization. * src/alloc.c (VBLOCK_BYTES_MIN, allocate_vectorlike, Fgarbage_collect): Use offsetof (struct, flex_array_member), not sizeof (struct), as that ports better to pre-C99 non-GCC. * src/chartab.c (Fmake_char_table, make_sub_char_table, copy_char_table): Use CHAR_TABLE_STANDARD_SLOTS rather than its definition, as the latter has changed. * src/conf_post.h (FLEXIBLE_ARRAY_MEMBER): Move here from w32.c, and port better to pre-C99 GCC. * src/image.c (struct xpm_cached_color): * src/lisp.h (struct Lisp_Vector, struct Lisp_Bool_Vector) (struct Lisp_Char_Table, struct Lisp_Sub_Char_Table): Use FLEXIBLE_ARRAY_MEMBER. * src/lisp.h (string_bytes) [GC_CHECK_STRING_BYTES]: Move decl to top level so it gets checked against implementation. (CHAR_TABLE_STANDARD_SLOTS): Adjust to struct Lisp_Char_Table change. * src/w32.c (FLEXIBLE_ARRAY_MEMBER): Move to conf_post.h.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog9
-rw-r--r--lib-src/ebrowse.c19
2 files changed, 19 insertions, 9 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 0e4cf0b2833..62ee45aac51 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,12 @@
+2013-06-21 Paul Eggert <eggert@cs.ucla.edu>
+
+ Use C99-style flexible array members if available.
+ * ebrowse.c (struct member, struct alias, struct sym):
+ Use FLEXIBLE_ARRAY_MEMBER.
+ (add_sym, add_member, make_namespace, register_namespace_alias):
+ Use offsetof (struct, flex_array_member), not sizeof (struct), as
+ that ports better to pre-C99 non-GCC.
+
2013-05-29 Eli Zaretskii <eliz@gnu.org>
* Makefile.in (mostlyclean): Remove *.res files.
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c
index 3a237daf5f8..81d0cf0a19e 100644
--- a/lib-src/ebrowse.c
+++ b/lib-src/ebrowse.c
@@ -237,7 +237,7 @@ struct member
char *def_regexp; /* Regular expression matching definition. */
const char *def_filename; /* File name of definition. */
int def_pos; /* Buffer position of definition. */
- char name[1]; /* Member name. */
+ char name[FLEXIBLE_ARRAY_MEMBER]; /* Member name. */
};
/* Structures of this type are used to connect class structures with
@@ -256,7 +256,7 @@ struct alias
struct alias *next; /* Next in list. */
struct sym *namesp; /* Namespace in which defined. */
struct link *aliasee; /* List of aliased namespaces (A::B::C...). */
- char name[1]; /* Alias name. */
+ char name[FLEXIBLE_ARRAY_MEMBER]; /* Alias name. */
};
/* The structure used to describe a class in the symbol table,
@@ -280,7 +280,7 @@ struct sym
const char *filename; /* File in which it can be found. */
const char *sfilename; /* File in which members can be found. */
struct sym *namesp; /* Namespace in which defined. . */
- char name[1]; /* Name of the class. */
+ char name[FLEXIBLE_ARRAY_MEMBER]; /* Name of the class. */
};
/* Experimental: Print info for `--position-info'. We print
@@ -567,8 +567,8 @@ add_sym (const char *name, struct sym *nested_in_class)
puts (name);
}
- sym = (struct sym *) xmalloc (sizeof *sym + strlen (name));
- memset (sym, 0, sizeof *sym);
+ sym = xmalloc (offsetof (struct sym, name) + strlen (name) + 1);
+ memset (sym, 0, offsetof (struct sym, name));
strcpy (sym->name, name);
sym->namesp = scope;
sym->next = class_table[h];
@@ -852,7 +852,8 @@ add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var,
static struct member *
add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
{
- struct member *m = (struct member *) xmalloc (sizeof *m + strlen (name));
+ struct member *m = xmalloc (offsetof (struct member, name)
+ + strlen (name) + 1);
struct member **list;
struct member *p;
struct member *prev;
@@ -962,8 +963,8 @@ mark_inherited_virtual (void)
static struct sym *
make_namespace (char *name, struct sym *context)
{
- struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name));
- memset (s, 0, sizeof *s);
+ struct sym *s = xmalloc (offsetof (struct sym, name) + strlen (name) + 1);
+ memset (s, 0, offsetof (struct sym, name));
strcpy (s->name, name);
s->next = all_namespaces;
s->namesp = context;
@@ -1046,7 +1047,7 @@ register_namespace_alias (char *new_name, struct link *old_name)
if (streq (new_name, al->name) && (al->namesp == current_namespace))
return;
- al = (struct alias *) xmalloc (sizeof *al + strlen (new_name));
+ al = xmalloc (offsetof (struct alias, name) + strlen (new_name) + 1);
strcpy (al->name, new_name);
al->next = namespace_alias_table[h];
al->namesp = current_namespace;