Skip to content

Commit f7d31ad

Browse files
committed
patch 9.1.0340: Problem: Error with matchaddpos() and empty list
Problem: Error with matchaddpos() and empty list (@rickhow) Solution: Return early for an empty list fixes: #14525 closes: #14563 Signed-off-by: Christian Brabandt <[email protected]>
1 parent 8560e6c commit f7d31ad

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/match.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ match_add(
8787
m = ALLOC_CLEAR_ONE(matchitem_T);
8888
if (m == NULL)
8989
return -1;
90-
if (pos_list != NULL)
90+
if (pos_list != NULL && pos_list->lv_len > 0)
9191
{
9292
m->mit_pos_array = ALLOC_CLEAR_MULT(llpos_T, pos_list->lv_len);
9393
if (m->mit_pos_array == NULL)
@@ -1294,7 +1294,7 @@ f_matchaddpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
12941294
return;
12951295
}
12961296
l = argvars[1].vval.v_list;
1297-
if (l == NULL)
1297+
if (l == NULL || l->lv_len == 0)
12981298
return;
12991299

13001300
if (argvars[2].v_type != VAR_UNKNOWN)

src/testdir/test_match.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ func Test_matchaddpos_error()
307307
" Why doesn't the following error have an error code E...?
308308
call assert_fails("call matchaddpos('Error', [{}])", 'E290:')
309309
call assert_equal(-1, matchaddpos('Error', test_null_list()))
310+
call assert_equal(-1, matchaddpos('Error', []))
310311
call assert_fails("call matchaddpos('Error', [1], [], 1)", 'E745:')
311312
call assert_equal(-1, matchaddpos('Search', [[]]))
312313
call assert_fails("call matchaddpos('Search', [[{}]])", 'E728:')
@@ -433,5 +434,4 @@ func Test_match_tab_with_linebreak()
433434
call StopVimInTerminal(buf)
434435
endfunc
435436

436-
437437
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
340,
707709
/**/
708710
339,
709711
/**/

0 commit comments

Comments
 (0)