Skip to content

Commit 7dc5e2e

Browse files
committed
patch 7.4.2160
Problem: setmatches() mixes up values. (Nikolai Pavlov) Solution: Save the string instead of reusing a shared buffer.
1 parent 5971dab commit 7dc5e2e

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/dict.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ dict_find(dict_T *d, char_u *key, int len)
418418
/*
419419
* Get a string item from a dictionary.
420420
* When "save" is TRUE allocate memory for it.
421+
* When FALSE a shared buffer is used, can only be used once!
421422
* Returns NULL if the entry doesn't exist or out of memory.
422423
*/
423424
char_u *

src/evalfunc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9659,11 +9659,11 @@ f_setmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
96599659
}
96609660
}
96619661

9662-
group = get_dict_string(d, (char_u *)"group", FALSE);
9662+
group = get_dict_string(d, (char_u *)"group", TRUE);
96639663
priority = (int)get_dict_number(d, (char_u *)"priority");
96649664
id = (int)get_dict_number(d, (char_u *)"id");
96659665
conceal = dict_find(d, (char_u *)"conceal", -1) != NULL
9666-
? get_dict_string(d, (char_u *)"conceal", FALSE)
9666+
? get_dict_string(d, (char_u *)"conceal", TRUE)
96679667
: NULL;
96689668
if (i == 0)
96699669
{
@@ -9677,6 +9677,8 @@ f_setmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
96779677
list_unref(s);
96789678
s = NULL;
96799679
}
9680+
vim_free(group);
9681+
vim_free(conceal);
96809682

96819683
li = li->li_next;
96829684
}

src/testdir/test_expr.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,12 @@ func Test_funcref()
194194
let OneByRef = funcref('One')
195195
call assert_equal(2, OneByRef())
196196
endfunc
197+
198+
func Test_setmatches()
199+
hi def link 1 Comment
200+
hi def link 2 PreProc
201+
let set = [{"group": 1, "pattern": 2, "id": 3, "priority": 4, "conceal": 5}]
202+
let exp = [{"group": '1', "pattern": '2', "id": 3, "priority": 4, "conceal": '5'}]
203+
call setmatches(set)
204+
call assert_equal(exp, getmatches())
205+
endfunc

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2160,
766768
/**/
767769
2159,
768770
/**/

0 commit comments

Comments
 (0)