]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.0.0606: cannot set the context for a specified quickfix list v8.0.0606
authorBram Moolenaar <Bram@vim.org>
Sun, 28 May 2017 06:16:25 +0000 (08:16 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 28 May 2017 06:16:25 +0000 (08:16 +0200)
Problem:    Cannot set the context for a specified quickfix list.
Solution:   Use the list index instead of the current list. (Yegappan
            Lakshmanan)

src/quickfix.c
src/testdir/test_quickfix.vim
src/version.c

index ce21661a655aa88b721767dd628356f0408258bb..6de55f75dc7f51421fcdbf3ae6ebeb86f2d792b0 100644 (file)
@@ -4881,7 +4881,9 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action)
        /* Use the specified quickfix/location list */
        if (di->di_tv.v_type == VAR_NUMBER)
        {
-           qf_idx = di->di_tv.vval.v_number - 1;
+           /* for zero use the current list */
+           if (di->di_tv.vval.v_number != 0)
+               qf_idx = di->di_tv.vval.v_number - 1;
            if (qf_idx < 0 || qf_idx >= qi->qf_listcount)
                return FAIL;
        }
@@ -4912,11 +4914,11 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action)
     if ((di = dict_find(what, (char_u *)"context", -1)) != NULL)
     {
        typval_T        *ctx;
-       free_tv(qi->qf_lists[qi->qf_curlist].qf_ctx);
+       free_tv(qi->qf_lists[qf_idx].qf_ctx);
        ctx =  alloc_tv();
        if (ctx != NULL)
            copy_tv(&di->di_tv, ctx);
-       qi->qf_lists[qi->qf_curlist].qf_ctx = ctx;
+       qi->qf_lists[qf_idx].qf_ctx = ctx;
     }
 
     return retval;
index f1fd3c97a17047e74d2ac767eccd7cd5eb124c8f..51f6a6f7cee01df50f951f47ffafaef552dbc159 100644 (file)
@@ -1804,6 +1804,37 @@ func Xproperty_tests(cchar)
        call setloclist(0, [], 'f')
        call assert_equal({}, getloclist(0, {'context':1}))
     endif
+
+    " Test for changing the context of previous quickfix lists
+    call g:Xsetlist([], 'f')
+    Xexpr "One"
+    Xexpr "Two"
+    Xexpr "Three"
+    call g:Xsetlist([], ' ', {'context' : [1], 'nr' : 1})
+    call g:Xsetlist([], ' ', {'context' : [2], 'nr' : 2})
+    " Also, check for setting the context using quickfix list number zero.
+    call g:Xsetlist([], ' ', {'context' : [3], 'nr' : 0})
+    call test_garbagecollect_now()
+    let l = g:Xgetlist({'nr' : 1, 'context' : 1})
+    call assert_equal([1], l.context)
+    let l = g:Xgetlist({'nr' : 2, 'context' : 1})
+    call assert_equal([2], l.context)
+    let l = g:Xgetlist({'nr' : 3, 'context' : 1})
+    call assert_equal([3], l.context)
+
+    " Test for changing the context through reference and for garbage
+    " collection of quickfix context
+    let l = ["red"]
+    call g:Xsetlist([], ' ', {'context' : l})
+    call add(l, "blue")
+    let x = g:Xgetlist({'context' : 1})
+    call add(x.context, "green")
+    call assert_equal(["red", "blue", "green"], l)
+    call assert_equal(["red", "blue", "green"], x.context)
+    unlet l
+    call test_garbagecollect_now()
+    let m = g:Xgetlist({'context' : 1})
+    call assert_equal(["red", "blue", "green"], m.context)
 endfunc
 
 func Test_qf_property()
@@ -2073,3 +2104,19 @@ func Test_qf_free()
   call XfreeTests('c')
   call XfreeTests('l')
 endfunc
+
+" Test for buffer overflow when parsing lines and adding new entries to
+" the quickfix list.
+func Test_bufoverflow()
+  set efm=%f:%l:%m
+  cgetexpr ['File1:100:' . repeat('x', 1025)]
+
+  set efm=%+GCompiler:\ %.%#,%f:%l:%m
+  cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World']
+
+  set efm=%DEntering\ directory\ %f,%f:%l:%m
+  cgetexpr ['Entering directory ' . repeat('a', 1006),
+             \ 'File1:10:Hello World']
+  set efm&vim
+endfunc
+
index 2c5aa06fde2cbb8c20d78f54aad0f8bbea28fc30..0daa3497d6595b34ca6a66dae1689a35da8dd155 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    606,
 /**/
     605,
 /**/