Subject: bug#58954: 28.2; ibuffer.el out of range error on lots of buffers?

From: Stefan Kangas <[email-masked]>
Date: Wed, 2 Nov 2022 06:03:01 -0700

"Chris Hecker" <[email-masked]> writes:

> I was getting Args out of range: #<buffer *Ibuffer*>, 51267, 51313
> when hitting C-x C-b with a ton of buffers open, lots of tramp
> buffers, some eww buffers, etc.
>
>   722 buffers 86533321 669 files, 2 processes

I can't reproduce that here.

> It's too much for me to try to repro for me right now with emacs -Q,
> but hopefully this will help:
>
> I debugged it to line 1980 in release 28.2 ibuffer.el in function
> ibuffer-map-lines:
>
>     (delete-region (line-beginning-position)
>         (1+ (line-end-position)))
>
> (line-end-position) evaluated to the end of the buffer, so 1+'ing it
> made delete-region error.  Changing it to:
>
>     (delete-region (line-beginning-position)
>         (min (point-max) (1+ (line-end-position))))
>
> made ibuffer work again.  I didn't look to closely to know if this was
> the result of some logic error earlier in the function, or if this
> should have a min guard on it normally or what.

The fix looks simple enough, but I'm uneasy about it.

`ibuffer-map-lines' seems to be mapping over buffers in *Ibuffer*, but
the last line in that buffer is not a buffer.  I have:

     600 buffers 44145326 489 files, 1 process

So my question is why `ibuffer-map-lines' is mapping over that last line
in your case?  Could you perhaps try stepping through this function
using edebug to figure out what might be going on?