aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2016-11-12 14:18:29 -0500
committerJames McCoy <jamessan@jamessan.com>2016-11-15 23:16:08 -0500
commitcaa33aaaf8b044cf3a8311213d0841d2d9e591a5 (patch)
tree824235f97311c4465105099577af9af5c565dd78
parentc0fd830be4ef3eafb756c463aee6408323ba4e58 (diff)
downloadrneovim-caa33aaaf8b044cf3a8311213d0841d2d9e591a5.tar.gz
rneovim-caa33aaaf8b044cf3a8311213d0841d2d9e591a5.tar.bz2
rneovim-caa33aaaf8b044cf3a8311213d0841d2d9e591a5.zip
vim-patch:7.4.1647
Problem: Using freed memory after setqflist() and ":caddbuffer". (Dominique) Solution: Set qf_ptr when adding the first item to the quickfix list. https://github.com/vim/vim/commit/8b20179c657b4266dff115486ca68c6a50324071
-rw-r--r--src/nvim/quickfix.c6
-rw-r--r--src/nvim/version.c2
-rw-r--r--test/functional/legacy/quickfix_spec.lua16
3 files changed, 22 insertions, 2 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 71fcb5e60f..6bb863985e 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -910,6 +910,8 @@ static int qf_add_entry(qf_info_T *qi, qfline_T **prevp, char_u *dir,
if (qi->qf_lists[qi->qf_curlist].qf_count == 0) {
/* first element in the list */
qi->qf_lists[qi->qf_curlist].qf_start = qfp;
+ qi->qf_lists[qi->qf_curlist].qf_ptr = qfp;
+ qi->qf_lists[qi->qf_curlist].qf_index = 0;
qfp->qf_prev = qfp; /* first element points to itself */
} else {
assert(*prevp);
@@ -3621,7 +3623,9 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title)
else
qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start;
- qi->qf_lists[qi->qf_curlist].qf_index = 1;
+ if (qi->qf_lists[qi->qf_curlist].qf_count > 0) {
+ qi->qf_lists[qi->qf_curlist].qf_index = 1;
+ }
qf_update_buffer(qi);
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 69438c50d0..7e88672e69 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -797,7 +797,7 @@ static int included_patches[] = {
// 1650,
1649,
1648,
- // 1647,
+ 1647,
// 1646 NA
// 1645,
// 1644,
diff --git a/test/functional/legacy/quickfix_spec.lua b/test/functional/legacy/quickfix_spec.lua
index 480e046f55..fa9ddc78ae 100644
--- a/test/functional/legacy/quickfix_spec.lua
+++ b/test/functional/legacy/quickfix_spec.lua
@@ -443,6 +443,17 @@ describe('helpgrep', function()
augroup! testgroup
endfunc
+
+ func Test_caddbuffer_to_empty()
+ helpgr quickfix
+ call setqflist([], 'r')
+ cad
+ call assert_fails('cn', 'E553:')
+ " Upstream calls quit! here to verify vim is still
+ " running, but that will be covered by the
+ " expected_empty() call in the busted test
+ " quit!
+ endfunc
]])
end)
@@ -522,6 +533,11 @@ describe('helpgrep', function()
call('XquickfixChangedByAutocmd', 'l')
expected_empty()
end)
+
+ it('does not crash after using caddbuffer with an empty qf list', function()
+ call('Test_caddbuffer_to_empty')
+ expected_empty()
+ end)
end)
describe('errorformat', function()