From 8ba492e4e2bff7104cdd1c3bcca8831e094ad193 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 13 Sep 2019 00:09:20 -0400 Subject: vim-patch:8.0.1772: quickfix: mixup of FALSE and FAIL, returning -1 Problem: Quickfix: mixup of FALSE and FAIL, returning -1. Solution: Use FAIL and INVALID_QFIDX. (Yegappan Lakshmanan) https://github.com/vim/vim/commit/29ce409bfca52bb8a07e2975d06fd788458e9861 --- src/nvim/quickfix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index be6e48465f..8d76863d90 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2209,7 +2209,7 @@ static int qf_jump_edit_buffer(qf_info_T *qi, qfline_T *qf_ptr, int forceit, // set b_p_ro flag). if (!can_abandon(curbuf, forceit)) { no_write_message(); - retval = false; + retval = FAIL; } else { retval = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1, ECMD_HIDE + ECMD_SET_HELP, @@ -2242,7 +2242,7 @@ static int qf_jump_edit_buffer(qf_info_T *qi, qfline_T *qf_ptr, int forceit, } if (*abort) { - retval = false; + retval = FAIL; } } @@ -4532,7 +4532,7 @@ int get_errorlist(const qf_info_T *qi_arg, win_T *wp, int qf_idx, list_T *list) } } - if (qf_idx == -1) { + if (qf_idx == INVALID_QFIDX) { qf_idx = qi->qf_curlist; } -- cgit From 4ef9ad0514bde2694ca51b0d48f86ffbb6384f56 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 13 Sep 2019 00:20:23 -0400 Subject: vim-patch:8.1.0248: duplicated quickfix code Problem: duplicated quickfix code. Solution: Move the code to a function. https://github.com/vim/vim/commit/8d8a65e389cef318ae661ff0fe7b1b00fd7cb25f --- src/nvim/quickfix.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 8d76863d90..d9f09dbb55 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3448,6 +3448,19 @@ static int qf_id2nr(const qf_info_T *const qi, const unsigned qfid) return INVALID_QFIDX; } +// Jump to the first entry if there is one. +static void qf_jump_first(qf_info_T *qi, unsigned save_qfid, int forceit) + FUNC_ATTR_NONNULL_ALL +{ + // If autocommands changed the current list, then restore it + if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { + qi->qf_curlist = qf_id2nr(qi, save_qfid); + } + if (qi->qf_lists[qi->qf_curlist].qf_count > 0) { + qf_jump(qi, 0, 0, forceit); + } +} + /* * Return TRUE when using ":vimgrep" for ":grep". */ @@ -3549,11 +3562,8 @@ void ex_make(exarg_T *eap) curbuf); } if (res > 0 && !eap->forceit && qflist_valid(wp, save_qfid)) { - // If autocommands changed the current list, then restore it. - if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { - qi->qf_curlist = qf_id2nr(qi, save_qfid); - } - qf_jump(qi, 0, 0, false); // display first error + // display the first error + qf_jump_first(qi, save_qfid, false); } cleanup: @@ -3919,11 +3929,8 @@ void ex_cfile(exarg_T *eap) // list. if (res > 0 && (eap->cmdidx == CMD_cfile || eap->cmdidx == CMD_lfile) && qflist_valid(wp, save_qfid)) { - // If autocommands changed the current list, then restore it - if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { - qi->qf_curlist = qf_id2nr(qi, save_qfid); - } - qf_jump(qi, 0, 0, eap->forceit); // display first error + // display the first error + qf_jump_first(qi, save_qfid, eap->forceit); } } @@ -5421,11 +5428,8 @@ void ex_cbuffer(exarg_T *eap) // free the list. if (res > 0 && (eap->cmdidx == CMD_cbuffer || eap->cmdidx == CMD_lbuffer) && qflist_valid(wp, save_qfid)) { - // If autocommands changed the current list, then restore it. - if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { - qi->qf_curlist = qf_id2nr(qi, save_qfid); - } - qf_jump(qi, 0, 0, eap->forceit); // display first error + // display the first error + qf_jump_first(qi, save_qfid, eap->forceit); } } } @@ -5503,11 +5507,8 @@ void ex_cexpr(exarg_T *eap) if (res > 0 && (eap->cmdidx == CMD_cexpr || eap->cmdidx == CMD_lexpr) && qflist_valid(wp, save_qfid)) { - // If autocommands changed the current list, then restore it. - if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { - qi->qf_curlist = qf_id2nr(qi, save_qfid); - } - qf_jump(qi, 0, 0, eap->forceit); + // display the first error + qf_jump_first(qi, save_qfid, eap->forceit); } } else { EMSG(_("E777: String or List expected")); -- cgit From fba9c724957f0a18cb42ffdb75375241da08c6c6 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 13 Sep 2019 00:38:42 -0400 Subject: vim-patch:8.1.0259: no test for fixed quickfix issue Problem: No test for fixed quickfix issue. Solution: Add a test. Clean up the code a bit. (Yegappan Lakshmanan) https://github.com/vim/vim/commit/3f347e4716c44cf6458be407e712e3d708d82580 --- src/nvim/quickfix.c | 15 ++++++++++++--- src/nvim/testdir/test_quickfix.vim | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index d9f09dbb55..6e14888ca8 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -728,6 +728,15 @@ static int qf_get_nextline(qfstate_T *state) return QF_OK; } +// Returns true if the specified quickfix/location list is empty. +static bool qf_list_empty(const qf_info_T *qi, int qf_idx) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT +{ + if (qi == NULL || qf_idx < 0 || qf_idx >= LISTCOUNT) { + return true; + } + return qi->qf_lists[qf_idx].qf_count <= 0; +} /// Parse a line and get the quickfix fields. /// Return the QF_ status. @@ -2906,8 +2915,7 @@ void qf_view_result(bool split) if (IS_LL_WINDOW(curwin)) { qi = GET_LOC_LIST(curwin); } - if (qi == NULL - || qi->qf_lists[qi->qf_curlist].qf_count == 0) { + if (qf_list_empty(qi, qi->qf_curlist)) { EMSG(_(e_quickfix)); return; } @@ -3456,7 +3464,8 @@ static void qf_jump_first(qf_info_T *qi, unsigned save_qfid, int forceit) if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { qi->qf_curlist = qf_id2nr(qi, save_qfid); } - if (qi->qf_lists[qi->qf_curlist].qf_count > 0) { + // Autocommands might have cleared the list, check for it + if (!qf_list_empty(qi, qi->qf_curlist)) { qf_jump(qi, 0, 0, forceit); } } diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index 440bf47f4b..16f008ca41 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -3515,6 +3515,30 @@ func Xautocmd_changelist(cchar) call assert_equal(5, line('.')) autocmd! QuickFixCmdPost + " Test for autocommands clearing the quickfix list before jumping to the + " first error. This should not result in an error + autocmd QuickFixCmdPost * call g:Xsetlist([], 'r') + let v:errmsg = '' + " Test for cfile/lfile + Xfile Xerr + call assert_true(v:errmsg !~# 'E42:') + " Test for cbuffer/lbuffer + edit Xerr + Xbuffer + call assert_true(v:errmsg !~# 'E42:') + " Test for cexpr/lexpr + Xexpr 'Xtestfile2:4:Line4' + call assert_true(v:errmsg !~# 'E42:') + " Test for grep/lgrep + " The grepprg may not be set on non-Unix systems + if has('unix') + silent Xgrep Line5 Xtestfile2 + call assert_true(v:errmsg !~# 'E42:') + endif + " Test for vimgrep/lvimgrep + call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:') + autocmd! QuickFixCmdPost + call delete('Xerr') call delete('Xtestfile1') call delete('Xtestfile2') -- cgit From 47357270aef74f901076df460c1eeb8dc5e7c6bf Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 13 Sep 2019 01:18:00 -0400 Subject: vim-patch:8.1.0261: Coverity complains about a negative array index Problem: Coverity complains about a negative array index. Solution: When qf_id2nr() cannot find the list then don't set qf_curlist. https://github.com/vim/vim/commit/38efd1d17a6e6aa2add71efdf2cde4a788e5f5e5 --- src/nvim/quickfix.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 6e14888ca8..51d6ab8289 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3456,14 +3456,27 @@ static int qf_id2nr(const qf_info_T *const qi, const unsigned qfid) return INVALID_QFIDX; } -// Jump to the first entry if there is one. -static void qf_jump_first(qf_info_T *qi, unsigned save_qfid, int forceit) +// If the current list is not "save_qfid" and we can find the list with that ID +// then make it the current list. +// This is used when autocommands may have changed the current list. +static void qf_restore_list(qf_info_T *qi, unsigned save_qfid) FUNC_ATTR_NONNULL_ALL { - // If autocommands changed the current list, then restore it if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { - qi->qf_curlist = qf_id2nr(qi, save_qfid); + const int curlist = qf_id2nr(qi, save_qfid); + if (curlist >= 0) { + qi->qf_curlist = curlist; + } + // else: what if the list can't be found? } +} + +// Jump to the first entry if there is one. +static void qf_jump_first(qf_info_T *qi, unsigned save_qfid, int forceit) + FUNC_ATTR_NONNULL_ALL +{ + qf_restore_list(qi, save_qfid); + // Autocommands might have cleared the list, check for it if (!qf_list_empty(qi, qi->qf_curlist)) { qf_jump(qi, 0, 0, forceit); @@ -4038,11 +4051,7 @@ static bool vgr_qflist_valid(win_T *wp, qf_info_T *qi, unsigned qfid, return true; } } - if (qi->qf_lists[qi->qf_curlist].qf_id != qfid) { - // Autocommands changed the quickfix list. Find the one we were using - // and restore it. - qi->qf_curlist = qf_id2nr(qi, qfid); - } + qf_restore_list(qi, qfid); return true; } @@ -4338,10 +4347,7 @@ void ex_vimgrep(exarg_T *eap) goto theend; } - // If autocommands changed the current list, then restore it. - if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { - qi->qf_curlist = qf_id2nr(qi, save_qfid); - } + qf_restore_list(qi, save_qfid); /* Jump to first match. */ if (qi->qf_lists[qi->qf_curlist].qf_count > 0) { @@ -4641,9 +4647,7 @@ static int qf_get_list_from_lines(dict_T *what, dictitem_T *di, dict_T *retdict) } list_T *l = tv_list_alloc(kListLenMayKnow); - qf_info_T *qi = xmalloc(sizeof(*qi)); - memset(qi, 0, sizeof(*qi)); - qi->qf_refcount++; + qf_info_T *const qi = ll_new_list(); if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat, true, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) { -- cgit From 5f95b35c7acb2de90cf55f7ea197254d70e07de9 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 13 Sep 2019 02:10:21 -0400 Subject: vim-patch:8.1.0267: no good check if restoring quickfix list worked Problem: No good check if restoring quickfix list worked. Solution: Let qf_restore_list() return OK/FAIL. (Yegappan Lakshmanan) https://github.com/vim/vim/commit/90f1e2b7bcf56112e1535b693acf131727179a6e --- src/nvim/quickfix.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 51d6ab8289..6c26e53cd7 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3459,25 +3459,30 @@ static int qf_id2nr(const qf_info_T *const qi, const unsigned qfid) // If the current list is not "save_qfid" and we can find the list with that ID // then make it the current list. // This is used when autocommands may have changed the current list. -static void qf_restore_list(qf_info_T *qi, unsigned save_qfid) - FUNC_ATTR_NONNULL_ALL +// Returns OK if successfully restored the list. Returns FAIL if the list with +// the specified identifier (save_qfid) is not found in the stack. +static int qf_restore_list(qf_info_T *qi, unsigned save_qfid) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { const int curlist = qf_id2nr(qi, save_qfid); - if (curlist >= 0) { - qi->qf_curlist = curlist; + if (curlist < 0) { + // list is not present + return FAIL; } - // else: what if the list can't be found? + qi->qf_curlist = curlist; } + return OK; } // Jump to the first entry if there is one. static void qf_jump_first(qf_info_T *qi, unsigned save_qfid, int forceit) FUNC_ATTR_NONNULL_ALL { - qf_restore_list(qi, save_qfid); - - // Autocommands might have cleared the list, check for it + if (qf_restore_list(qi, save_qfid) == FAIL) { + return; + } + // Autocommands might have cleared the list, check for that if (!qf_list_empty(qi, qi->qf_curlist)) { qf_jump(qi, 0, 0, forceit); } @@ -4051,7 +4056,9 @@ static bool vgr_qflist_valid(win_T *wp, qf_info_T *qi, unsigned qfid, return true; } } - qf_restore_list(qi, qfid); + if (qf_restore_list(qi, qfid) == FAIL) { + return false; + } return true; } @@ -4347,7 +4354,9 @@ void ex_vimgrep(exarg_T *eap) goto theend; } - qf_restore_list(qi, save_qfid); + if (qf_restore_list(qi, save_qfid) == FAIL) { + goto theend; + } /* Jump to first match. */ if (qi->qf_lists[qi->qf_curlist].qf_count > 0) { -- cgit