fix(prompt): ml_get error with invalid ': lnum

Problem: internal error E315 in init_prompt if ': has an invalid line number.

Solution: clamp the line number.
This commit is contained in:
Sean Dewar
2026-02-15 01:27:25 +00:00
parent 4afbc25432
commit b3096b5860
2 changed files with 11 additions and 0 deletions

View File

@@ -1593,6 +1593,10 @@ static void init_prompt(int cmdchar_todo)
char *prompt = prompt_text();
int prompt_len = (int)strlen(prompt);
// In case the mark is set to a nonexistent line.
curbuf->b_prompt_start.mark.lnum = MIN(curbuf->b_prompt_start.mark.lnum,
curbuf->b_ml.ml_line_count);
curwin->w_cursor.lnum = MAX(curwin->w_cursor.lnum, curbuf->b_prompt_start.mark.lnum);
char *text = ml_get(curbuf->b_prompt_start.mark.lnum);
colnr_T text_len = ml_get_len(curbuf->b_prompt_start.mark.lnum);

View File

@@ -671,6 +671,13 @@ describe('prompt buffer', function()
-- No crash from invalid col.
eq(true, api.nvim_buf_set_mark(0, ':', fn('line', '.'), 999, {}))
eq({ 12, 6 }, api.nvim_buf_get_mark(0, ':'))
-- No ml_get error from invalid lnum.
command('set messagesopt+=wait:0 messagesopt-=hit-enter')
fn('setpos', "':", { 0, 999, 7, 0 })
eq('', api.nvim_get_vvar('errmsg'))
command('set messagesopt&')
eq({ 12, 6 }, api.nvim_buf_get_mark(0, ':'))
end)
describe('prompt_getinput', function()