commit c6f0a1920630d5d4059781c03a8ddae804d805bc
parent 53ac2ad20ab26b147d64da48a5e3684c2541c844
Author: zeertzjq <zeertzjq@outlook.com>
Date: Fri, 8 Aug 2025 06:14:17 +0800
vim-patch:8.1.0425: ml_get error and crash with appendbufline()
Problem: ml_get error and crash with appendbufline(). (Masashi Iizuka)
Solution: Set per-window buffer info. (Hirohito Higashi, closes vim/vim#3455)
https://github.com/vim/vim/commit/9cea87c5775948a35098f3602746c20ecf95dbcd
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat:
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
@@ -1729,6 +1729,9 @@ static void enter_buffer(buf_T *buf)
// mark cursor position as being invalid
curwin->w_valid = 0;
+ buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.mark.lnum,
+ curbuf->b_last_cursor.mark.col, true);
+
// Make sure the buffer is loaded.
if (curbuf->b_ml.ml_mfp == NULL) { // need to load the file
// If there is no filetype, allow for detecting one. Esp. useful for
diff --git a/test/old/testdir/test_bufline.vim b/test/old/testdir/test_bufline.vim
@@ -158,6 +158,33 @@ func Test_appendbufline()
exe "bwipe! " . b
endfunc
+func Test_appendbufline_no_E315()
+ let after = [
+ \ 'set stl=%f ls=2',
+ \ 'new',
+ \ 'let buf = bufnr("%")',
+ \ 'quit',
+ \ 'vsp',
+ \ 'exec "buffer" buf',
+ \ 'wincmd w',
+ \ 'call appendbufline(buf, 0, "abc")',
+ \ 'redraw',
+ \ 'while getbufline(buf, 1)[0] =~ "^\\s*$"',
+ \ ' sleep 10m',
+ \ 'endwhile',
+ \ 'au VimLeavePre * call writefile([v:errmsg], "Xerror")',
+ \ 'au VimLeavePre * call writefile(["done"], "Xdone")',
+ \ 'qall!',
+ \ ]
+ if !RunVim([], after, '--clean')
+ return
+ endif
+ call assert_notmatch("^E315:", readfile("Xerror")[0])
+ call assert_equal("done", readfile("Xdone")[0])
+ call delete("Xerror")
+ call delete("Xdone")
+endfunc
+
func Test_deletebufline()
new
let b = bufnr('%')