aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.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/image.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/image.c')
-rw-r--r--src/image.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/image.c b/src/image.c
index 7a554ef1b63..f15c2788967 100644
--- a/src/image.c
+++ b/src/image.c
@@ -30,7 +30,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30#endif 30#endif
31 31
32#include <setjmp.h> 32#include <setjmp.h>
33
33#include <c-ctype.h> 34#include <c-ctype.h>
35#include <flexmember.h>
34 36
35#include "lisp.h" 37#include "lisp.h"
36#include "frame.h" 38#include "frame.h"
@@ -3347,7 +3349,7 @@ xpm_cache_color (struct frame *f, char *color_name, XColor *color, int bucket)
3347 if (bucket < 0) 3349 if (bucket < 0)
3348 bucket = xpm_color_bucket (color_name); 3350 bucket = xpm_color_bucket (color_name);
3349 3351
3350 nbytes = offsetof (struct xpm_cached_color, name) + strlen (color_name) + 1; 3352 nbytes = FLEXSIZEOF (struct xpm_cached_color, name, strlen (color_name) + 1);
3351 p = xmalloc (nbytes); 3353 p = xmalloc (nbytes);
3352 strcpy (p->name, color_name); 3354 strcpy (p->name, color_name);
3353 p->color = *color; 3355 p->color = *color;
@@ -8328,8 +8330,8 @@ static struct animation_cache *
8328imagemagick_create_cache (char *signature) 8330imagemagick_create_cache (char *signature)
8329{ 8331{
8330 struct animation_cache *cache 8332 struct animation_cache *cache
8331 = xmalloc (offsetof (struct animation_cache, signature) 8333 = xmalloc (FLEXSIZEOF (struct animation_cache, signature,
8332 + strlen (signature) + 1); 8334 strlen (signature) + 1));
8333 cache->wand = 0; 8335 cache->wand = 0;
8334 cache->index = 0; 8336 cache->index = 0;
8335 cache->next = 0; 8337 cache->next = 0;