Subject: Re: bug#31316: Emacs hangs in `font_open_entity'

From: Werner LEMBERG <[email-masked]>
Date: Tue, 08 May 2018 22:49:30 +0200 (CEST)

For completeness:

> Attached. It contains all breaks between loading the test file in
> GB18030 encoding and displaying something on screen.
> 
> This is still emacs bca6c434 (Apr 29).

... with the following local patches (which don't influence the
selection of fonts, still leading to the problematic `Emmentaler'
font).

    Werner

PS: Why doesn't produce the `pp' command (from emacs's `.gdbinit'
    file) any output in `gdb.txt' if activated with `set logging on'?

======================================================================

diff --git a/lisp/international/fontset.el b/lisp/international/fontset.el
index 4a7b754791..47f8c9ad3a 100644
--- a/lisp/international/fontset.el
+++ b/lisp/international/fontset.el
@@ -53,7 +53,7 @@
        ("ascii-0$" . ascii)
        ("gb2312.1980" . chinese-gb2312)
        ("gbk" . chinese-gbk)
-       ("gb18030" . (unicode . nil))
+       ("gb18030" . (gb18030 . unicode))
        ("jisx0208.1978" . japanese-jisx0208-1978)
        ("jisx0208" . japanese-jisx0208)
        ("jisx0201" . jisx0201)
diff --git a/src/font.c b/src/font.c
index ef3f92b594..daa6be00e6 100644
--- a/src/font.c
+++ b/src/font.c
@@ -2901,7 +2901,9 @@ font_open_entity (struct frame *f, Lisp_Object entity, int pixel_size)
   for (psize = pixel_size; ; psize++)
     {
       font_object = driver_list->driver->open (f, entity, psize);
-      if (NILP (font_object))
+      if (NILP (font_object)
+         /* Avoid an infinite loop.  */
+         || psize > pixel_size + 100)
        return Qnil;
       font = XFONT_OBJECT (font_object);
       if (font->average_width > 0 && font->height > 0)