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)
diff --git a/src/regexp.c b/src/regexp.c
index 229f6ef..375731c 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -2543,6 +2543,7 @@
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
index 61c9cb3..a137aa5 100644
--- a/src/testdir/test_substitute.vim
+++ b/src/testdir/test_substitute.vim
@@ -881,6 +881,12 @@
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
index 36416ef..cf7de76 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1621,
+/**/
1620,
/**/
1619,