]> granicus.if.org Git - vim/commitdiff
patch 7.4.2160 v7.4.2160
authorBram Moolenaar <Bram@vim.org>
Fri, 5 Aug 2016 20:22:06 +0000 (22:22 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 5 Aug 2016 20:22:06 +0000 (22:22 +0200)
Problem:    setmatches() mixes up values. (Nikolai Pavlov)
Solution:   Save the string instead of reusing a shared buffer.

src/dict.c
src/evalfunc.c
src/testdir/test_expr.vim
src/version.c

index 9c590064cceaa7ca185f61e8dd4278a90b4fbfbe..30a15a6f077c604bd50b9fb656a92e1a9945f16f 100644 (file)
@@ -418,6 +418,7 @@ dict_find(dict_T *d, char_u *key, int len)
 /*
  * Get a string item from a dictionary.
  * When "save" is TRUE allocate memory for it.
+ * When FALSE a shared buffer is used, can only be used once!
  * Returns NULL if the entry doesn't exist or out of memory.
  */
     char_u *
index 00956612f8d9d2584c4f52470c1edfd88166ed57..dc0e630af88ff18b53c01ec212c7c952a1692d27 100644 (file)
@@ -9659,11 +9659,11 @@ f_setmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
                }
            }
 
-           group = get_dict_string(d, (char_u *)"group", FALSE);
+           group = get_dict_string(d, (char_u *)"group", TRUE);
            priority = (int)get_dict_number(d, (char_u *)"priority");
            id = (int)get_dict_number(d, (char_u *)"id");
            conceal = dict_find(d, (char_u *)"conceal", -1) != NULL
-                             ? get_dict_string(d, (char_u *)"conceal", FALSE)
+                             ? get_dict_string(d, (char_u *)"conceal", TRUE)
                              : NULL;
            if (i == 0)
            {
@@ -9677,6 +9677,8 @@ f_setmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
                list_unref(s);
                s = NULL;
            }
+           vim_free(group);
+           vim_free(conceal);
 
            li = li->li_next;
        }
index 0800039aee1a161ac8fe6246ab845f0c1311c8e5..557d74960f7e3df6a276014c95fbd55e53eb8e83 100644 (file)
@@ -194,3 +194,12 @@ func Test_funcref()
   let OneByRef = funcref('One')
   call assert_equal(2, OneByRef())
 endfunc
+
+func Test_setmatches()
+  hi def link 1 Comment
+  hi def link 2 PreProc
+  let set = [{"group": 1, "pattern": 2, "id": 3, "priority": 4, "conceal": 5}]
+  let exp = [{"group": '1', "pattern": '2', "id": 3, "priority": 4, "conceal": '5'}]
+  call setmatches(set)
+  call assert_equal(exp, getmatches())
+endfunc
index 1c83d6e7b8f53fac3887a3631dfccb563a3a0201..94e14bff86553a555be8b0abf2f43e0b1526d502 100644 (file)
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2160,
 /**/
     2159,
 /**/