Subject: bug#38564: 27.0.50; macOS "emacs -nw" git-gutter-mode segfault

From: Mike Hamrick <[email-masked]>
Date: Fri, 20 Dec 2019 12:21:40 -0800

Robert Pluim writes:
> I was, but I thought the previous version should work as well. Hmm, is
> FRAME_DISPLAY_INFO guaranteed to be initialized?

The stack trace I posted on Thursday the 19th, was built from d55f2f7,
which is a number of commits after your commit ea84a95 which updated
ns_color_index_to_rbga() to test for a non-null FRAME_DISPLAY_INFO
pointer.

I think the problem here is that FRAME_DISPLAY_INFO references
f->output_data which is a union.

#define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)

  union output_data
  {
    struct tty_output *tty;     /* From termchar.h.  */
    struct x_output *x;         /* From xterm.h.  */
    struct w32_output *w32;     /* From w32term.h.  */
    struct ns_output *ns;       /* From nsterm.h.  */
  }

In the case of a tty frame, we're going to be dereferencing a struct
tty_output *, rather than a struct ns_ouput *, and when that happens
sometimes the "display_info" offset into the tty_output struct may
or my not luckily land on patch of NULL bytes.

Robert Pluim also wrote:
> Mike, could you try the following?

Yup, I'm running with that patch now. This should stop the function
extend_face_to_end_of_line() from ever calling ns_color_index_to_rgba()
when you're in a tty frame, which I think will fix this for good.

I've taken to running my emacs 27 server process in the debugger, so if I
get any more crashes I should have more stack traces for ya.

Thanks!

Mike