diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-03-24 12:29:26 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-03-26 09:02:42 +0800 |
commit | 19bbc43947a75b0279f9697f5830a238af337c5b (patch) | |
tree | 35afd1ea37b8c1d9140a0c2dc685f63e7c0c2b92 /src/nvim/buffer.c | |
parent | 9530c2d6d82dbae1303e15608c56f4fefad312a9 (diff) | |
download | rneovim-19bbc43947a75b0279f9697f5830a238af337c5b.tar.gz rneovim-19bbc43947a75b0279f9697f5830a238af337c5b.tar.bz2 rneovim-19bbc43947a75b0279f9697f5830a238af337c5b.zip |
vim-patch:8.2.4281: using freed memory with :lopen and :bwipe
Problem: Using freed memory with :lopen and :bwipe.
Solution: Do not use a wiped out buffer.
https://github.com/vim/vim/commit/9b4a80a66544f2782040b641498754bcb5b8d461
Cherry-pick some indent changes from patch 8.2.1432.
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r-- | src/nvim/buffer.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index f200f16a5f..8d042525d3 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1486,8 +1486,15 @@ void set_curbuf(buf_T *buf, int action) // An autocommand may have deleted "buf", already entered it (e.g., when // it did ":bunload") or aborted the script processing! // If curwin->w_buffer is null, enter_buffer() will make it valid again - if ((buf_valid(buf) && buf != curbuf && !aborting()) || curwin->w_buffer == NULL) { - enter_buffer(buf); + bool valid = buf_valid(buf); + if ((valid && buf != curbuf && !aborting()) || curwin->w_buffer == NULL) { + // If the buffer is not valid but curwin->w_buffer is NULL we must + // enter some buffer. Using the last one is hopefully OK. + if (!valid) { + enter_buffer(lastbuf); + } else { + enter_buffer(buf); + } if (old_tw != curbuf->b_p_tw) { check_colorcolumn(curwin); } |