0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.1621: crash when using submatch(0, 1) in substitute()

Problem:    Crash when using submatch(0, 1) in substitute().
Solution:   Increment reference count. (closes #6887)
This commit is contained in:
Bram Moolenaar
2020-09-06 15:14:45 +02:00
parent 4140c4f3ff
commit 8a0dcf4330
3 changed files with 9 additions and 0 deletions

View File

@@ -2543,6 +2543,7 @@ reg_submatch_list(int no)
list_free(list); list_free(list);
return NULL; return NULL;
} }
++list->lv_refcount;
return list; return list;
} }
#endif #endif

View File

@@ -881,6 +881,12 @@ func Test_invalid_submatch()
call assert_equal([], submatch(1, 1)) call assert_equal([], submatch(1, 1))
endfunc endfunc
func Test_submatch_list_concatenate()
let pat = 'A\(.\)'
let Rep = {-> string([submatch(0, 1)] + [[submatch(1)]])}
call substitute('A1', pat, Rep, '')->assert_equal("[['A1'], ['1']]")
endfunc
func Test_substitute_expr_arg() func Test_substitute_expr_arg()
call assert_equal('123456789-123456789=', substitute('123456789', call assert_equal('123456789-123456789=', substitute('123456789',
\ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1621,
/**/ /**/
1620, 1620,
/**/ /**/