From: Eli Zaretskii Date: Sat, 12 Aug 2023 12:06:48 +0000 (+0300) Subject: Avoid crashes in 'display_count_lines' when current buffer was killed X-Git-Tag: emacs-29.1.90~214 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8dbd5aa1eef;p=emacs.git 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) --- 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. */