* src/ftcrfont.c (ftcrfont_open): Initialize the max_width field

On a 32bit build, Emacs can otherwise crash with a !FIXNUM_OVERFLOW_P
assertion in `Ffont_info` by simply doing `emacs -Q` and then `C-s`.

* src/font.c: Try and detect uninitialized `max_width` fields.
(font_make_object): Set max_width to a silly value.
(Ffont_info): Check the value is not silly any more.
This commit is contained in:
Stefan Monnier 2020-10-08 09:49:20 -04:00
parent d340a979db
commit c7804ac401
2 changed files with 11 additions and 1 deletions

View file

@ -188,6 +188,9 @@ font_make_object (int size, Lisp_Object entity, int pixelsize)
FONT_OBJECT_MAX, PVEC_FONT);
int i;
/* Poison the max_width, so we can detect when it hasn't been set. */
eassert (font->max_width = 1024 * 1024 * 1024);
/* GC can happen before the driver is set up,
so avoid dangling pointer here (Bug#17771). */
font->driver = NULL;
@ -5171,6 +5174,9 @@ If the named font cannot be opened and loaded, return nil. */)
return Qnil;
font = XFONT_OBJECT (font_object);
/* Sanity check to make sure we have initialized max_width. */
eassert (XFONT_OBJECT (font_object)->max_width < 1024 * 1024 * 1024);
info = CALLN (Fvector,
AREF (font_object, FONT_NAME_INDEX),
AREF (font_object, FONT_FULLNAME_INDEX),

View file

@ -187,7 +187,8 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
block_input ();
cairo_glyph_t stack_glyph;
font->min_width = font->average_width = font->space_width = 0;
font->min_width = font->max_width = 0;
font->average_width = font->space_width = 0;
for (char c = 32; c < 127; c++)
{
cairo_glyph_t *glyphs = &stack_glyph;
@ -211,6 +212,8 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
&& (! font->min_width
|| font->min_width > this_width))
font->min_width = this_width;
if (this_width > font->max_width)
font->max_width = this_width;
if (c == 32)
font->space_width = this_width;
font->average_width += this_width;
@ -266,6 +269,7 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
font->relative_compose = 0;
font->default_ascent = 0;
font->vertical_centering = false;
eassert (font->max_width < 512 * 1024 * 1024);
return font_object;
}