diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-02-02 02:56:28 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-02-11 15:27:57 +0100 |
commit | 5ae90c84eadb4ebc910824627fb91d386cf2bd48 (patch) | |
tree | 90e0b999a4ec1f2112f53780bced634735c53048 /src | |
parent | e578d586f28160d684087bae99482ab3912d3770 (diff) | |
download | rneovim-5ae90c84eadb4ebc910824627fb91d386cf2bd48.tar.gz rneovim-5ae90c84eadb4ebc910824627fb91d386cf2bd48.tar.bz2 rneovim-5ae90c84eadb4ebc910824627fb91d386cf2bd48.zip |
vim-patch:8.0.1402: crash with nasty autocommand
Problem: Crash with nasty autocommand. (gy741, Dominique Pelle)
Solution: Check that the new current buffer isn't wiped out. (closes vim/vim#2447)
https://github.com/vim/vim/commit/9bca805ec49eb0d2d0d0b2093f418ff425500169
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/buffer.c | 15 | ||||
-rw-r--r-- | src/nvim/testdir/test_autocmd.vim | 3 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index a86a908492..8d0738dd29 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1387,20 +1387,25 @@ void set_curbuf(buf_T *buf, int action) /* Don't restart Select mode after switching to another buffer. */ VIsual_reselect = FALSE; - /* close_windows() or apply_autocmds() may change curbuf */ + // close_windows() or apply_autocmds() may change curbuf and wipe out "buf" prevbuf = curbuf; - bufref_T bufref; - set_bufref(&bufref, prevbuf); + bufref_T newbufref; + bufref_T prevbufref; + set_bufref(&prevbufref, prevbuf); + set_bufref(&newbufref, buf); + // Autocommands may delete the curren buffer and/or the buffer we wan to go + // to. In those cases don't close the buffer. if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, false, curbuf) - || (bufref_valid(&bufref) && !aborting())) { + || (bufref_valid(&prevbufref) && bufref_valid(&newbufref) + && !aborting())) { if (prevbuf == curwin->w_buffer) { reset_synblock(curwin); } if (unload) { close_windows(prevbuf, false); } - if (bufref_valid(&bufref) && !aborting()) { + if (bufref_valid(&prevbufref) && !aborting()) { win_T *previouswin = curwin; if (prevbuf == curbuf) u_sync(FALSE); diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index f41c1983a9..16cf6965bd 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -434,6 +434,7 @@ func s:AutoCommandOptionSet(match) endfunc func Test_OptionSet() + throw 'skipped: Nvim does not support test_override()' if !has("eval") || !has("autocmd") || !exists("+autochdir") return endif @@ -573,6 +574,7 @@ func Test_OptionSet() endfunc func Test_OptionSet_diffmode() + throw 'skipped: Nvim does not support test_override()' call test_override('starting', 1) " 18: Changing an option when enetering diff mode new @@ -606,6 +608,7 @@ func Test_OptionSet_diffmode() endfunc func Test_OptionSet_diffmode_close() + throw 'skipped: Nvim does not support test_override()' call test_override('starting', 1) " 19: Try to close the current window when entering diff mode " should not segfault |