[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master c7804ac: * src/ftcrfont.c (ftcrfont_open): Initialize the `max_wi
From: |
Stefan Monnier |
Subject: |
master c7804ac: * src/ftcrfont.c (ftcrfont_open): Initialize the `max_width` field |
Date: |
Thu, 8 Oct 2020 09:49:24 -0400 (EDT) |
branch: master
commit c7804ac4018fb03787f291d7ef1739b34914d930
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* 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.
---
src/font.c | 6 ++++++
src/ftcrfont.c | 6 +++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/font.c b/src/font.c
index 20686ce..fe257f4 100644
--- a/src/font.c
+++ b/src/font.c
@@ -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),
diff --git a/src/ftcrfont.c b/src/ftcrfont.c
index 7832d4f..4892a34 100644
--- a/src/ftcrfont.c
+++ b/src/ftcrfont.c
@@ -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;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master c7804ac: * src/ftcrfont.c (ftcrfont_open): Initialize the `max_width` field,
Stefan Monnier <=