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)
This commit is contained in:
Eli Zaretskii 2020-10-03 20:49:18 +03:00
parent f4305f3b53
commit 0fe8ab79e7

View file

@ -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);