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

From: Gerd Möllmann <[email-masked]>
Date: Tue, 25 Mar 2025 06:06:29 +0100

Gerd Möllmann <[email-masked]> writes:

>> Something like that, yes.
>
> Or maybe simply use the glyph at string - 1 when cur_x == last column.
> STRING is always part of a row, and we don't have rows that are
> only partially filled, or are so narrow that string - 1 isn't valid.

Like this:

diff --git a/src/term.c b/src/term.c
index a66cec252d5..46b3db7abeb 100644
--- a/src/term.c
+++ b/src/term.c
@@ -972,10 +972,18 @@ tty_write_glyphs (struct frame *f, struct glyph *string, int len)
   if (AutoWrap (tty)
       && curY (tty) + 1 == FRAME_TOTAL_LINES (f)
       && curX (tty) + len == FRAME_COLS (f)
-      && curX (tty) < FRAME_COLS (f) - 1
       && len > 0)
     {
-      /* Write glyphs except the first. */
+      /* If only outputting 1 glyph in the last column, make that two so
+	 that we have something to shift into the last column.  */
+      if (curX (tty) == FRAME_COLS (f) - 1)
+	{
+	  cmgoto (tty, curY (tty), curX (tty) - 1);
+	  --string;
+	  ++len;
+	}
+
+      /* Write glyphs except the first.  */
       int old_x = curX (tty), old_y = curY (tty);
       tty_write_glyphs_1 (f, string + 1, len - 1);

Sorry for being terse, have to get the train now :-).