Mercurial > vim
changeset 22143:3ec9e302ec94 v8.2.1621
patch 8.2.1621: crash when using submatch(0, 1) in substitute()
Commit: https://github.com/vim/vim/commit/8a0dcf43305586853f452a77fa295b0c8d54b463
Author: Bram Moolenaar <Bram@vim.org>
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 06 Sep 2020 15:15:04 +0200 |
parents | 572e3d7849e5 |
children | 4b18f34f4a66 |
files | src/regexp.c src/testdir/test_substitute.vim src/version.c |
diffstat | 3 files changed, 9 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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', \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',