Subject: bug#75725: SIGSEGV in emacs 30.0.93

From: Florian Franzmann <[email-masked]>
Date: Tue, 21 Jan 2025 14:13:38 +0100

On Di 2025-01-21 14:31:00 +0200, Eli Zaretskii wrote:
> > Date: Tue, 21 Jan 2025 09:15:30 +0100
> > From: Florian Franzmann <[email-masked]>
> > 
> > I'm experiencing a segmentation violation in emacs 30.0.93 when linked against GTK.
> > The crash does not happen in the TUI version of emacs (which, obviously, is not
> > linked against GTK).
> > 
> > Backtrace:
> > 
> > #0  normal_char_ascent_descent (font=0x0, c=c@entry=-1, ascent=ascent@entry=0x7fffffff2ad0, descent=descent@entry=0x7fffffff2ad4)
> >     at xdisp.c:30407
> > #1  0x000000000043b18b in normal_char_height (font=<optimized out>, c=c@entry=-1) at xdisp.c:30443
> > #2  0x0000000000455cdf in handle_single_display_spec (it=it@entry=0x7fffffff3150, spec=<optimized out>, spec@entry=0x28266e3,
> >     object=<optimized out>, object@entry=0x28dc604, overlay=overlay@entry=0x0, position=position@entry=0x7fffffff32b8,
> >     bufpos=bufpos@entry=0, display_replaced=0, frame_window_p=true, enable_eval_p=true) at xdisp.c:6114
> > #3  0x00000000004567de in handle_display_spec (it=it@entry=0x7fffffff3150, spec=<optimized out>, spec@entry=0x28266e3,
> >     object=object@entry=0x28dc604, overlay=0x0, position=position@entry=0x7fffffff32b8, bufpos=bufpos@entry=0, frame_window_p=true)
> >     at xdisp.c:5862
> 
> Thanks, I installed a trivial fix.  You may not like the results, but
> at least Emacs should not crash.
Thanks, that fixed the crash. However, I think it would make sense to
output some kind of useful information somewhere to help with
debugging such issues. Right now it's just a silent error.

Florian

> 
> I'm guessing the actual reason for this is that you have some
> problematic setup of fonts, which causes some character on the mode
> line to have no font for some reason.  So if loading the session which
> previously crashed produces some weird display on the mode line, try
> looking at your font/fontset setup to solve this.
> 
> (Of course, if Emacs still crashes after you update from Git or patch
> it with the patch below, please report the backtrace from the crash,
> maybe I missed something.)
> 
> Here's the patch which I installed on the emacs-30 branch:
> 
> diff --git a/src/xdisp.c b/src/xdisp.c
> index 19ce5b7..f11a8aa 100644
> --- a/src/xdisp.c
> +++ b/src/xdisp.c
> @@ -6111,7 +6111,9 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
>  	    {
>  	      struct face *face = FACE_FROM_ID (it->f, it->face_id);
>  	      it->voffset = - (XFLOATINT (value)
> -			       * (normal_char_height (face->font, -1)));
> +			       * (face->font
> +				  ? normal_char_height (face->font, -1)
> +				  : FRAME_LINE_HEIGHT (it->f)));
>  	    }
>  #endif /* HAVE_WINDOW_SYSTEM */
>  	}
> @@ -32056,7 +32058,8 @@ produce_stretch_glyph (struct it *it)
>    /* Compute height.  */
>    if (FRAME_WINDOW_P (it->f))
>      {
> -      int default_height = normal_char_height (font, ' ');
> +      int default_height =
> +	font ? normal_char_height (font, ' ') : FRAME_LINE_HEIGHT (it->f);
>  
>        if ((prop = plist_get (plist, QCheight), !NILP (prop))
>  	  && calc_pixel_width_or_height (&tem, it, prop, font, false, NULL))

--