Subject: 31.0.50; crash if message starts with a space and then without it

From: Daniel Clemente <[email-masked]>
Date: Mon, 24 Mar 2025 09:42:52 +0000

Believe it or not, this crashes each time. Open emacs -Q (with or
without daemon) in a TTY, and evaluate the first part and then the progn:

(modify-frame-parameters (selected-frame) '(
      ;; background-color needs to be defined, to crash. The precise
color doesn't matter
      (background-color . "#111")
      ;; Doesn't affect the crash:
      ;; (foreground-color . "#c0c0c0")
     ))
(progn
  (message " AB")
  (message "AB")
)

Conditions for this crash:
- the same message must have appeared with an initial space and
without an initial space. Use " ABC" and "AB" and it won't crash,
because ABC != AB. But use " ABC" and "ABC" and it crashes
- it must be in this order: first with space, then without
- both messages must be contained in a progn or in a let/while/defun…
If you evaluate each message separately, it works
- the background-color needs to be set
- there must only be 1 space in the beginning. With 2 spaces or 1 tab
or 1 dot it works. Space in the end also works

This is with latest Emacs compiled right now. It seems due to recent
changes since I didn't see it in my previous version (~2 weeks old),
but I'm not sure and I didn't have time to do bisecting. Line numbers
in my
backtrace might be off by 1 since I added some lines with comments
(but it also crashes without my edits).

Discovered by running zone-pgm-stress, which triggers the condition.

Crash:

Breakpoint 1, terminate_due_to_signal (sig=6, backtrace_limit=40) at emacs.c:425
425      signal (sig, SIG_DFL);
(gdb) bt
#0  terminate_due_to_signal (sig=6, backtrace_limit=40) at emacs.c:425
#1  0x00005555556cb0b7 in emacs_abort () at sysdep.c:2378
#2  0x00005555556730a9 in cmcheckmagic (tty=0x555555a983a0) at cm.c:122
#3  0x0000555555677abd in tty_write_glyphs_1 (f=0x555555aa46e0,
string=0x7ffff6ea3670, len=1)
    at term.c:816
#4  0x0000555555678430 in tty_write_glyphs (f=0x555555aa46e0,
string=0x7ffff6ea3638, len=1)
    at term.c:992
#5  0x000055555568358b in write_glyphs (f=0x555555aa46e0,
string=0x7ffff6ea3638, len=1)
    at terminal.c:182
#6  0x0000555555593388 in write_row (f=0x555555aa46e0, vpos=60,
updating_menu_p=false)
    at dispnew.c:6159
#7  0x00005555555912d1 in write_matrix (f=0x555555aa46e0,
inhibit_id_p=true, updating_menu_p=false)
    at dispnew.c:5746
#8  0x000055555558d69b in combine_updates_for_frame (f=0x555555aa46e0,
inhibit_scrolling=true)
    at dispnew.c:4053
#9  0x00005555555cebfc in echo_area_display (update_frame_p=true) at
xdisp.c:13562
#10 0x00005555555ca99e in message3_nolog (m=XIL(0x555555da1a04)) at
xdisp.c:12460
#11 0x00005555555ca64c in message3 (m=XIL(0x555555da1a04)) at xdisp.c:12390
#12 0x000055555576f5c1 in Fmessage (nargs=1, args=0x7fffffffbb00) at
editfns.c:3127
[…]
(gdb) frame 2
#2  0x00005555556730a9 in cmcheckmagic (tty=0x555555a983a0) at cm.c:122
122        emacs_abort ();
(gdb) list
117      if (frame_size_change_delayed (XFRAME (tty->top_frame)))
118        return;
119      if (curX (tty) == FrameCols (tty))
120        {
121          if (!MagicWrap (tty) || curY (tty) >= FrameRows (tty) - 1)
122        emacs_abort ();
123          if (tty->termscript)
124        putc ('\r', tty->termscript);
125          putc ('\r', tty->output);
126          if (tty->termscript)
(gdb) p curY(tty)
$1 = 60
(gdb) p FrameRows(tty)-1
$2 = 60
(gdb) p FrameCols(tty)
$3 = 100
(gdb)

In GNU Emacs 31.0.50 (build 28, x86_64-pc-linux-gnu) of 2025-03-24 built
 on sonn
Repository revision: 0cfe700e336da3cc5a2a766840d375921dcd5ee9
Repository branch: master
System Description: Devuan GNU/Linux 5 (daedalus)

Configured using:
 'configure --prefix=/opt/dc/emacs-dev/ --with-tiff=no --without-tiff
 --without-libsystemd --without-dbus --with-mailutils --without-modules
 --with-native-compilation=no --with-x-toolkit=no --without-imagemagick
 --without-xft --without-harfbuzz --without-freetype --without-libotf
 --without-xwidgets --without-xpm --without-jpeg --without-gif
 --without-png --without-webp --without-rsvg --without-cairo --without-x
 --without-sound --enable-checking=yes,glyphs --enable-profiling CC=gcc
 'CFLAGS=-g3 -O0 ''

Configured features:
GMP GNUTLS LCMS2 LIBSELINUX LIBXML2 NOTIFY INOTIFY PDUMPER SECCOMP
SQLITE3 THREADS XIM ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=SCIM
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  server-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/w/emacs-dev/lisp/pulse hides /w/emacs-dev/lisp/cedet/pulse

Features:
(shadow sort hashcash pcase cl-macs regexp-opt mail-extr emacsbug
message mailcap yank-media puny dired dnd dired-loaddefs rfc822 mml
mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util
text-property-search time-date subr-x mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
term/rxvt term/xterm xterm byte-opt gv bytecomp byte-compile server rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads inotify lcms2 multi-tty
make-network-process tty-child-frames emacs)

Memory information:
((conses 16 52990 10439) (symbols 48 6510 1) (strings 32 16235 1652)
 (string-bytes 1 429445) (vectors 16 8416) (vector-slots 8 76621 5913)
 (floats 8 33 11518) (intervals 56 248 14) (buffers 984 12))