From 0fe8ab79e7a2306b84e209cc4e90da1996da1cad Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 3 Oct 2020 20:49:18 +0300 Subject: [PATCH] Avoid segfaults in lookup_image when faces were freed * src/image.c (lookup_image): Make sure the frame's face cache exists and has at least the basic faces. If FACE_ID is not a basic face, and is no longer cached, fall back on the 'default' face. (Bug#43700) --- src/image.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/image.c b/src/image.c index 6ecf6a70fe2..25d5af8a8d5 100644 --- a/src/image.c +++ b/src/image.c @@ -2329,8 +2329,14 @@ lookup_image (struct frame *f, Lisp_Object spec, int face_id) struct image *img; EMACS_UINT hash; - struct face *face = (face_id >= 0) ? FACE_FROM_ID (f, face_id) - : FACE_FROM_ID (f, DEFAULT_FACE_ID); + if (FRAME_FACE_CACHE (f) == NULL) + init_frame_faces (f); + if (FRAME_FACE_CACHE (f)->used == 0) + recompute_basic_faces (f); + if (face_id < 0 || face_id >= FRAME_FACE_CACHE (f)->used) + face_id = DEFAULT_FACE_ID; + + struct face *face = FACE_FROM_ID (f, face_id); unsigned long foreground = FACE_COLOR_TO_PIXEL (face->foreground, f); unsigned long background = FACE_COLOR_TO_PIXEL (face->background, f); -- 2.39.5