mirror of
https://github.com/neovim/neovim.git
synced 2026-05-04 21:15:09 +00:00
fix(prompt): prompt_setprompt with unloaded buffer, ': with lnum 0
Problem: prompt_setprompt memory leak/other issues when fixing prompt line for unloaded buffer, or when ': line number is zero. Solution: don't fix prompt line for unloaded buffer. Clamp ': lnum above zero.
This commit is contained in:
@@ -1594,8 +1594,8 @@ static void init_prompt(int cmdchar_todo)
|
||||
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);
|
||||
curbuf->b_prompt_start.mark.lnum = MAX(1, 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);
|
||||
|
||||
@@ -772,9 +772,10 @@ void f_prompt_setprompt(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
|
||||
// Update the prompt-text and prompt-marks if a plugin calls prompt_setprompt()
|
||||
// even while user is editing their input.
|
||||
if (bt_prompt(buf)) {
|
||||
if (bt_prompt(buf) && buf->b_ml.ml_mfp != NULL) {
|
||||
// In case the mark is set to a nonexistent line.
|
||||
buf->b_prompt_start.mark.lnum = MIN(buf->b_prompt_start.mark.lnum, buf->b_ml.ml_line_count);
|
||||
buf->b_prompt_start.mark.lnum = MAX(1, MIN(buf->b_prompt_start.mark.lnum,
|
||||
buf->b_ml.ml_line_count));
|
||||
|
||||
linenr_T prompt_lno = buf->b_prompt_start.mark.lnum;
|
||||
char *old_prompt = buf_prompt_text(buf);
|
||||
|
||||
Reference in New Issue
Block a user