Subject: bug#50096: args-out-of-range in redisplay_internal

From: Eli Zaretskii <[email-masked]>
Date: Thu, 19 Aug 2021 10:32:14 +0300

> From: Juri Linkov <[email-masked]>
> Cc: [email-masked]
> Date: Wed, 18 Aug 2021 10:42:23 +0300
> 
> 1. message3_nolog calls echo_area_display
> 2. echo_area_display calls redisplay_internal

This step 2 happens only if display of the mini-window needs to resize
the mini-window for some reason.  When that happens, we need to
perform a thorough redisplay (as opposed to just redisplaying the
mini-window), because the bottom-most window needs to be resized as
result of resizing the mini-window.

> 3. redisplay_internal clears all matrices with clear_desired_matrices
> 4. redisplay_internal calls echo_area_display
>    that temporarily changes mini_window's buffer
>    from " *Minibuf-0*" to " *Echo Area 0*".
>    This updates w->desired_matrix to contain information
>    about " *Echo Area 0*" displayed in the mini_window.
>    But unwind_with_echo_area_buffer immediately
>    changes mini_window's buffer back to empty " *Minibuf-0*".
> 5. redisplay_internal calls hscroll_window_tree
>    where cursor_row already contains information
>    that was valid when " *Echo Area 0*" was temporarily
>    displayed in mini_window:

And step 5 says that you have somehow set up auto-hscroll in the
mini-window.  Which means the lines in the mini-window are truncated?
Does that also mean you set max-mini-window-height to 1?  But if so,
how come Emacs decided above that the mini-window needs to be resized?

So please show your customizations that seem to be parts of this
puzzle.  I think if these customizations are set up, a simple call to
'message' with a long enough string should be able to reproduce the
problem and allow debugging it.

> (gdb) l
> 14896		    cursor_row = MATRIX_ROW (w->desired_matrix, w->cursor.vpos);
> (gdb) p *cursor_row
> ...
>   start = {
>     pos = {
>       charpos = 1737,
>       bytepos = 1737
>     },
> ...
>   end = {
>     pos = {
>       charpos = 2150,
>       bytepos = 2150
> 
> These numbers are valid positions in " *Echo Area 0*"
> that was temporarily displayed in mini_window,
> but now mini_window's buffer is empty " *Minibuf-0*".

This means that the window's desired_matrix was produced for another
buffer, and is no longer valid.  That buffer is supposed to be
recorded in desired_matrix->buffer, please show it.