From 8dbd5aa1eef9db956ad3a4ed73add23fe0e48268 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 12 Aug 2023 15:06:48 +0300 Subject: [PATCH] Avoid crashes in 'display_count_lines' when current buffer was killed * src/xdisp.c (Fformat_mode_line): * src/fns.c (Fline_number_at_pos): Don't allow to count lines in a dead buffer. (Bug#65060) --- src/fns.c | 3 +++ src/xdisp.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/fns.c b/src/fns.c index 2ed62d6e8c6..af5f9479a36 100644 --- a/src/fns.c +++ b/src/fns.c @@ -6123,6 +6123,9 @@ from the absolute start of the buffer, disregarding the narrowing. */) { ptrdiff_t pos_byte, start_byte = BEGV_BYTE; + if (!BUFFER_LIVE_P (current_buffer)) + error ("Attempt to count lines in a dead buffer"); + if (MARKERP (position)) { /* We don't trust the byte position if the marker's buffer is diff --git a/src/xdisp.c b/src/xdisp.c index 22508978298..11417070804 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -27653,6 +27653,8 @@ are the selected window and the WINDOW's buffer). */) if (NILP (buffer)) buffer = w->contents; CHECK_BUFFER (buffer); + if (!BUFFER_LIVE_P (XBUFFER (buffer))) + error ("Attempt to format a mode line for a dead buffer"); /* Make formatting the modeline a non-op when noninteractive, otherwise there will be problems later caused by a partially initialized frame. */ -- 2.39.2