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. */