# HG changeset patch # User Bram Moolenaar # Date 1599398104 -7200 # Node ID 3ec9e302ec940b355cf074a5d72b14a7bc5c5b65 # Parent 572e3d7849e5a15346e53edec5fdb38603badbbf patch 8.2.1621: crash when using submatch(0, 1) in substitute() Commit: https://github.com/vim/vim/commit/8a0dcf43305586853f452a77fa295b0c8d54b463 Author: Bram Moolenaar Date: Sun Sep 6 15:14:45 2020 +0200 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 https://github.com/vim/vim/issues/6887) diff --git a/src/regexp.c b/src/regexp.c --- a/src/regexp.c +++ b/src/regexp.c @@ -2543,6 +2543,7 @@ reg_submatch_list(int no) list_free(list); return NULL; } + ++list->lv_refcount; return list; } #endif diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim --- a/src/testdir/test_substitute.vim +++ b/src/testdir/test_substitute.vim @@ -881,6 +881,12 @@ func Test_invalid_submatch() call assert_equal([], submatch(1, 1)) 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() call assert_equal('123456789-123456789=', substitute('123456789', \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1621, +/**/ 1620, /**/ 1619,