Skip to content

Commit 8b20179

Browse files
committed
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.
1 parent 4c90861 commit 8b20179

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/quickfix.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,8 @@ qf_add_entry(
10271027
/* first element in the list */
10281028
{
10291029
qi->qf_lists[qi->qf_curlist].qf_start = qfp;
1030+
qi->qf_lists[qi->qf_curlist].qf_ptr = qfp;
1031+
qi->qf_lists[qi->qf_curlist].qf_index = 0;
10301032
qfp->qf_prev = qfp; /* first element points to itself */
10311033
}
10321034
else
@@ -4113,7 +4115,8 @@ set_errorlist(
41134115
else
41144116
qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
41154117
qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start;
4116-
qi->qf_lists[qi->qf_curlist].qf_index = 1;
4118+
if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
4119+
qi->qf_lists[qi->qf_curlist].qf_index = 1;
41174120

41184121
#ifdef FEAT_WINDOWS
41194122
qf_update_buffer(qi);

src/testdir/test_quickfix.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,11 @@ function Test_quickfix_was_changed_by_autocmd()
679679
call XquickfixChangedByAutocmd('c')
680680
call XquickfixChangedByAutocmd('l')
681681
endfunction
682+
683+
func Test_caddbuffer_to_empty()
684+
helpgr quickfix
685+
call setqflist([], 'r')
686+
cad
687+
call assert_fails('cn', 'E553:')
688+
quit!
689+
endfunc

src/version.c

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

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1647,
751753
/**/
752754
1646,
753755
/**/

0 commit comments

Comments
 (0)