From: Paul Eggert Date: Tue, 20 Aug 2013 00:51:35 +0000 (-0700) Subject: * image.c (SIGNATURE_DIGESTSIZE): Remove. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1686^2~169 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8c2f38aaab7a7a2f0605416fc2ee38701e41ab61;p=emacs.git * image.c (SIGNATURE_DIGESTSIZE): Remove. (struct animation_cache): Make signature a flexible array member. All uses changed. This is a tad slower but may insulate us better from future changes to ImageMagick. --- diff --git a/src/ChangeLog b/src/ChangeLog index d0bafd3914e..e21d82bdc09 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2013-08-20 Paul Eggert + + * image.c (SIGNATURE_DIGESTSIZE): Remove. + (struct animation_cache): Make signature a flexible array member. + All uses changed. This is a tad slower but may insulate us better + from future changes to ImageMagick. + 2013-08-19 Paul Eggert * image.c: Shrink memory needed for animation cache. diff --git a/src/image.c b/src/image.c index 4970d40af33..2db44d07c81 100644 --- a/src/image.c +++ b/src/image.c @@ -7876,17 +7876,13 @@ imagemagick_filename_hint (Lisp_Object spec, char hint_buffer[MaxTextExtent]) separate from the image cache, because the images may be scaled before display. */ -/* Size of ImageMagick image signatures, in bytes. It's SHA-256 as a - hex string, so it's 256 bits represented via 4 bits per byte. */ -enum { SIGNATURE_DIGESTSIZE = 256 / 4 }; - struct animation_cache { MagickWand *wand; int index; EMACS_TIME update_time; struct animation_cache *next; - char signature[SIGNATURE_DIGESTSIZE]; + char signature[FLEXIBLE_ARRAY_MEMBER]; }; static struct animation_cache *animation_cache = NULL; @@ -7894,11 +7890,13 @@ static struct animation_cache *animation_cache = NULL; static struct animation_cache * imagemagick_create_cache (char *signature) { - struct animation_cache *cache = xmalloc (sizeof *cache); + struct animation_cache *cache + = xmalloc (offsetof (struct animation_cache, signature) + + strlen (signature) + 1); cache->wand = 0; cache->index = 0; cache->next = 0; - memcpy (cache->signature, signature, SIGNATURE_DIGESTSIZE); + strcpy (cache->signature, signature); return cache; } @@ -7932,7 +7930,6 @@ imagemagick_get_animation_cache (MagickWand *wand) struct animation_cache *cache; struct animation_cache **pcache = &animation_cache; - eassert (strlen (signature) == SIGNATURE_DIGESTSIZE); imagemagick_prune_animation_cache (); while (1) @@ -7943,7 +7940,7 @@ imagemagick_get_animation_cache (MagickWand *wand) *pcache = cache = imagemagick_create_cache (signature); break; } - if (memcmp (signature, cache->signature, SIGNATURE_DIGESTSIZE) == 0) + if (strcmp (signature, cache->signature) == 0) break; pcache = &cache->next; }