fix(terminal): crash after deleting buffer lines (#37921)

Problem:  Terminal crashes after deleting buffer lines.
Solution: Don't insert lines above lines 0.
This commit is contained in:
zeertzjq
2026-02-17 21:00:13 +08:00
committed by GitHub
parent bd12aef784
commit f3feae0bbf
2 changed files with 27 additions and 0 deletions

View File

@@ -2470,6 +2470,8 @@ static void refresh_scrollback(Terminal *term, buf_T *buf)
deleted--; deleted--;
} }
// Clamp old_height in case buffer lines have been deleted by the user.
old_height = MIN(old_height, buf->b_ml.ml_line_count);
while (term->sb_pending > 0) { while (term->sb_pending > 0) {
// This means that either the window height has decreased or the screen // This means that either the window height has decreased or the screen
// became full and libvterm had to push all rows up. Convert the first // became full and libvterm had to push all rows up. Convert the first

View File

@@ -1101,6 +1101,31 @@ describe('pending scrollback line handling', function()
]] ]]
assert_alive() assert_alive()
end) end)
it('does not crash after deleting buffer lines', function()
local buf = api.nvim_get_current_buf()
local chan = api.nvim_open_term(buf, {})
api.nvim_chan_send(chan, ('a\n'):rep(11) .. 'a')
screen:expect([[
^a |
a |*5
|
]])
api.nvim_set_option_value('modifiable', true, { buf = buf })
api.nvim_buf_set_lines(buf, 0, -1, true, {})
screen:expect([[
^ |
{1:~ }|*5
|
]])
api.nvim_chan_send(chan, ('\nb'):rep(11) .. '\n')
screen:expect([[
b |*5
^ |
|
]])
assert_alive()
end)
end) end)
describe('scrollback is correct', function() describe('scrollback is correct', function()