Avoid rare crashes due to "C-g C-g" on TTY frames
authorEli Zaretskii <eliz@gnu.org>
Sun, 23 Mar 2025 11:17:06 +0000 (13:17 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 23 Mar 2025 19:34:20 +0000 (20:34 +0100)
* src/term.c (tty_send_additional_strings): Don't use SBYTES, as
this function could be called in the middle of GC.  (Bug#77205)

(cherry picked from commit 939a2a3c2dd60503c6ebef839b5f05f962d405ce)

src/term.c

index e15b7a0887ebcac3d6042535e11ede24dbe37e9d..32f3c8c48d6320a6f085832d62c017e4e812bdf1 100644 (file)
@@ -184,9 +184,15 @@ tty_send_additional_strings (struct terminal *terminal, Lisp_Object sym)
       Lisp_Object string = XCAR (extra_codes);
       if (STRINGP (string))
         {
-         fwrite (SDATA (string), 1, SBYTES (string), tty->output);
+         struct Lisp_String *str = XSTRING (string);
+         /* Don't use SBYTES, as that is not protected from GC.  */
+         ptrdiff_t sbytes
+           = (str->u.s.size_byte < 0
+              ? str->u.s.size & ~ARRAY_MARK_FLAG
+              : str->u.s.size_byte);
+         fwrite (SDATA (string), 1, sbytes, tty->output);
           if (tty->termscript)
-           fwrite (SDATA (string), 1, SBYTES (string), tty->termscript);
+           fwrite (SDATA (string), 1, sbytes, tty->termscript);
         }
     }
 }