Skip to content

Commit 9cea87c

Browse files
committed
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 #3455)
1 parent e76d7a6 commit 9cea87c

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/buffer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ can_unload_buffer(buf_T *buf)
428428

429429
FOR_ALL_WINDOWS(wp)
430430
if (wp->w_buffer == buf)
431+
{
431432
can_unload = FALSE;
433+
break;
434+
}
432435
}
433436
if (!can_unload)
434437
EMSG(_("E937: Attempt to delete a buffer that is in use"));
@@ -1742,6 +1745,9 @@ enter_buffer(buf_T *buf)
17421745
/* mark cursor position as being invalid */
17431746
curwin->w_valid = 0;
17441747

1748+
buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.lnum,
1749+
curbuf->b_last_cursor.col, TRUE);
1750+
17451751
/* Make sure the buffer is loaded. */
17461752
if (curbuf->b_ml.ml_mfp == NULL) /* need to load the file */
17471753
{

src/testdir/test_bufline.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,33 @@ func Test_appendbufline()
9191
exe "bwipe! " . b
9292
endfunc
9393

94+
func Test_appendbufline_no_E315()
95+
let after = [
96+
\ 'set stl=%f ls=2',
97+
\ 'new',
98+
\ 'let buf = bufnr("%")',
99+
\ 'quit',
100+
\ 'vsp',
101+
\ 'exec "buffer" buf',
102+
\ 'wincmd w',
103+
\ 'call appendbufline(buf, 0, "abc")',
104+
\ 'redraw',
105+
\ 'while getbufline(buf, 1)[0] =~ "^\\s*$"',
106+
\ ' sleep 10m',
107+
\ 'endwhile',
108+
\ 'au VimLeavePre * call writefile([v:errmsg], "Xerror")',
109+
\ 'au VimLeavePre * call writefile(["done"], "Xdone")',
110+
\ 'qall!',
111+
\ ]
112+
if !RunVim([], after, '--clean')
113+
return
114+
endif
115+
call assert_notmatch("^E315:", readfile("Xerror")[0])
116+
call assert_equal("done", readfile("Xdone")[0])
117+
call delete("Xerror")
118+
call delete("Xdone")
119+
endfunc
120+
94121
func Test_deletebufline()
95122
new
96123
let b = bufnr('%')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ static char *(features[]) =
794794

795795
static int included_patches[] =
796796
{ /* Add new patch number below this line */
797+
/**/
798+
425,
797799
/**/
798800
424,
799801
/**/

0 commit comments

Comments
 (0)