aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/image.c b/src/image.c
index c085e6e63eb..1f8cb520dca 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1569,7 +1569,7 @@ which is then usually a filename. */)
1569 1569
1570DEFUN ("image-flush", Fimage_flush, Simage_flush, 1570DEFUN ("image-flush", Fimage_flush, Simage_flush,
1571 1, 2, 0, 1571 1, 2, 0,
1572 doc: /* Fush the image with specification SPEC on frame FRAME. 1572 doc: /* Flush the image with specification SPEC on frame FRAME.
1573This removes the image from the Emacs image cache. If SPEC specifies 1573This removes the image from the Emacs image cache. If SPEC specifies
1574an image file, the next redisplay of this image will read from the 1574an image file, the next redisplay of this image will read from the
1575current contents of that file. 1575current contents of that file.
@@ -2276,23 +2276,28 @@ slurp_file (char *file, ptrdiff_t *size)
2276 unsigned char *buf = NULL; 2276 unsigned char *buf = NULL;
2277 struct stat st; 2277 struct stat st;
2278 2278
2279 if (fp && fstat (fileno (fp), &st) == 0 2279 if (fp)
2280 && 0 <= st.st_size && st.st_size <= min (PTRDIFF_MAX, SIZE_MAX)
2281 && (buf = xmalloc (st.st_size),
2282 fread (buf, 1, st.st_size, fp) == st.st_size))
2283 {
2284 *size = st.st_size;
2285 fclose (fp);
2286 }
2287 else
2288 { 2280 {
2289 if (fp) 2281 ptrdiff_t count = SPECPDL_INDEX ();
2290 fclose (fp); 2282 record_unwind_protect_ptr (fclose_unwind, fp);
2291 if (buf) 2283
2284 if (fstat (fileno (fp), &st) == 0
2285 && 0 <= st.st_size && st.st_size < min (PTRDIFF_MAX, SIZE_MAX))
2292 { 2286 {
2293 xfree (buf); 2287 /* Report an error if we read past the purported EOF.
2294 buf = NULL; 2288 This can happen if the file grows as we read it. */
2289 ptrdiff_t buflen = st.st_size;
2290 buf = xmalloc (buflen + 1);
2291 if (fread (buf, 1, buflen + 1, fp) == buflen)
2292 *size = buflen;
2293 else
2294 {
2295 xfree (buf);
2296 buf = NULL;
2297 }
2295 } 2298 }
2299
2300 unbind_to (count, Qnil);
2296 } 2301 }
2297 2302
2298 return buf; 2303 return buf;
@@ -5732,8 +5737,8 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5732 if (fread (sig, 1, sizeof sig, fp) != sizeof sig 5737 if (fread (sig, 1, sizeof sig, fp) != sizeof sig
5733 || fn_png_sig_cmp (sig, 0, sizeof sig)) 5738 || fn_png_sig_cmp (sig, 0, sizeof sig))
5734 { 5739 {
5735 image_error ("Not a PNG file: `%s'", file, Qnil);
5736 fclose (fp); 5740 fclose (fp);
5741 image_error ("Not a PNG file: `%s'", file, Qnil);
5737 return 0; 5742 return 0;
5738 } 5743 }
5739 } 5744 }
@@ -7581,8 +7586,7 @@ gif_load (struct frame *f, struct image *img)
7581 delay |= ext->Bytes[1]; 7586 delay |= ext->Bytes[1];
7582 } 7587 }
7583 } 7588 }
7584 img->lisp_data = Fcons (Qextension_data, 7589 img->lisp_data = list2 (Qextension_data, img->lisp_data);
7585 Fcons (img->lisp_data, Qnil));
7586 if (delay) 7590 if (delay)
7587 img->lisp_data 7591 img->lisp_data
7588 = Fcons (Qdelay, 7592 = Fcons (Qdelay,