]> granicus.if.org Git - vim/commitdiff
patch 8.2.1621: crash when using submatch(0, 1) in substitute() v8.2.1621
authorBram Moolenaar <Bram@vim.org>
Sun, 6 Sep 2020 13:14:45 +0000 (15:14 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 6 Sep 2020 13:14:45 +0000 (15:14 +0200)
Problem:    Crash when using submatch(0, 1) in substitute().
Solution:   Increment reference count. (closes #6887)

src/regexp.c
src/testdir/test_substitute.vim
src/version.c

index 229f6ef2b7cb643d5f276f834371d6a6f4bf2e05..375731c3cdfca477dfba67cc2f5982c5cb00a374 100644 (file)
@@ -2543,6 +2543,7 @@ reg_submatch_list(int no)
        list_free(list);
        return NULL;
     }
+    ++list->lv_refcount;
     return list;
 }
 #endif
index 61c9cb34e5d323f59f6c02ab883730a6859d2223..a137aa5272ddd34907ba8508586b152b6c2674f9 100644 (file)
@@ -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',
        \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
index 36416ef1710ea138cdb400b03a40fa809138d3b1..cf7de76a62aea88e50a691fd25daf19e2e75b2fe 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1621,
 /**/
     1620,
 /**/