bug#81510: 31.0.90; NS (macOS): clicking a disabled (:enable nil) tab-bar item crases Emacs

Eli Zaretskii <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
> From: Al Haji-Ali <[email protected]>
> Date: Tue, 28 Jul 2026 16:25:33 +0100
> 
> 
> Clicking a tab-bar menu-item that has an explicit `:enable nil' property
> (i.e. a disabled item) crashes Emacs outright on the NS (macOS) port.
> 
> Minimal recipe:
> 
>     emacs -Q -l repro.el
> 
> where repro.el contains:
> 
>     (defun repro-tab-bar-format ()
>       '((disabled-item menu-item "disabled item -- click me" ignore
>          :enable nil)))
>     (setq tab-bar-format '(repro-tab-bar-format))
>     (tab-bar-mode 1)
> 
> Then click on the "disabled item -- click me" text in the tab bar and
> note the crash.
> 
> Backtrace (macOS crash report, Thread 0):
> 
>     0   libsystem_kernel.dylib   __pthread_kill + 8
>     1   libsystem_pthread.dylib  pthread_kill + 296
>     2   libsystem_c.dylib        raise + 32
>     3   Emacs                    terminate_due_to_signal + 228
>     4   Emacs                    emacs_abort + 20
>     5   Emacs                    kbd_buffer_store_buffered_event + 652
>     6   Emacs                    ns_read_socket_1 + 112
>     7   Emacs                    gobble_input + 264
>     ...
>     -[EmacsView mouseDown:]
> 
> Root cause, as far as I can tell from reading src/xdisp.c,
> src/keyboard.c and src/nsterm.m:
> 
> 1. keyboard.c's parse_tab_bar_item defaults TAB_BAR_ITEM_ENABLED_P to t,
>    and an explicit `:enable FORM' property overrides it.
> 
> 2. xdisp.c's handle_tab_bar_click returns nil on a disabled item, rather
>    than (Fcons (Qtab_bar, Qnil)) like a missed clicked.
> 
> 3. nsterm.m's -[EmacsView mouseDown:] does:
> 
>        if (!(tab_bar_p && NILP (tab_bar_arg)))
>          emacs_event->kind = MOUSE_CLICK_EVENT;
>        ...
>        EV_TRAILER (theEvent);
> 
>    For a disabled item, emacs_event->kind is never assigned -- it's left
>    at its default, NO_EVENT. EV_TRAILER then calls
>    kbd_buffer_store_event_hold.
> 
> 4. keyboard.c's kbd_buffer_store_buffered_event opens with:
> 
>        if (event->kind == NO_EVENT)
>          emacs_abort ();
> 
> I have not tested on X11/w32, so I am not sure if they have the same
> issue.

No, they both assign 'kind' unconditionally.  They then assign the
'arg' member only if tab_bar_arg is non-nil.

> Possible minimal fix: make handle_tab_bar_click's disabled-item
> branch return (Fcons (Qtab_bar, Qnil)) instead of bare Qnil, matching
> the "click missed" case, which nsterm.m (and presumably the other
> ports) already handle correctly as a harmless plain click. I haven't
> verified this doesn't have side effects for other callers of
> handle_tab_bar_click across the X11/w32 ports.

I prefer that nsterm.m is changed to do the same we do in xterm.c and
w32term.c.  There's no need to change xdisp.c, which is a back-end
independent part of the display engine.

Alan, WDYT?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.