Mercurial > vim
comparison src/regexp.c @ 18572:23fef64352a1 v8.1.2280
patch 8.1.2280: crash when passing partial to substitute()
Commit: https://github.com/vim/vim/commit/b0745b221d284e381f1bd4b591cd68ea54b6a51d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 9 22:28:11 2019 +0100
patch 8.1.2280: crash when passing partial to substitute()
Problem: Crash when passing partial to substitute().
Solution: Take extra arguments into account. (closes https://github.com/vim/vim/issues/5186)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 09 Nov 2019 22:30:04 +0100 |
parents | 68fd5296bf73 |
children | e9675870c480 |
comparison
equal
deleted
inserted
replaced
18571:e268594d460a | 18572:23fef64352a1 |
---|---|
1782 #endif | 1782 #endif |
1783 | 1783 |
1784 #ifdef FEAT_EVAL | 1784 #ifdef FEAT_EVAL |
1785 | 1785 |
1786 /* | 1786 /* |
1787 * Put the submatches in "argv[0]" which is a list passed into call_func() by | 1787 * Put the submatches in "argv[argskip]" which is a list passed into |
1788 * vim_regsub_both(). | 1788 * call_func() by vim_regsub_both(). |
1789 */ | 1789 */ |
1790 static int | 1790 static int |
1791 fill_submatch_list(int argc UNUSED, typval_T *argv, int argcount) | 1791 fill_submatch_list(int argc UNUSED, typval_T *argv, int argskip, int argcount) |
1792 { | 1792 { |
1793 listitem_T *li; | 1793 listitem_T *li; |
1794 int i; | 1794 int i; |
1795 char_u *s; | 1795 char_u *s; |
1796 | 1796 typval_T *listarg = argv + argskip; |
1797 if (argcount == 0) | 1797 |
1798 /* called function doesn't take an argument */ | 1798 if (argcount == argskip) |
1799 return 0; | 1799 // called function doesn't take a submatches argument |
1800 | 1800 return argskip; |
1801 /* Relies on sl_list to be the first item in staticList10_T. */ | 1801 |
1802 init_static_list((staticList10_T *)(argv->vval.v_list)); | 1802 // Relies on sl_list to be the first item in staticList10_T. |
1803 | 1803 init_static_list((staticList10_T *)(listarg->vval.v_list)); |
1804 /* There are always 10 list items in staticList10_T. */ | 1804 |
1805 li = argv->vval.v_list->lv_first; | 1805 // There are always 10 list items in staticList10_T. |
1806 li = listarg->vval.v_list->lv_first; | |
1806 for (i = 0; i < 10; ++i) | 1807 for (i = 0; i < 10; ++i) |
1807 { | 1808 { |
1808 s = rsm.sm_match->startp[i]; | 1809 s = rsm.sm_match->startp[i]; |
1809 if (s == NULL || rsm.sm_match->endp[i] == NULL) | 1810 if (s == NULL || rsm.sm_match->endp[i] == NULL) |
1810 s = NULL; | 1811 s = NULL; |
1812 s = vim_strnsave(s, (int)(rsm.sm_match->endp[i] - s)); | 1813 s = vim_strnsave(s, (int)(rsm.sm_match->endp[i] - s)); |
1813 li->li_tv.v_type = VAR_STRING; | 1814 li->li_tv.v_type = VAR_STRING; |
1814 li->li_tv.vval.v_string = s; | 1815 li->li_tv.vval.v_string = s; |
1815 li = li->li_next; | 1816 li = li->li_next; |
1816 } | 1817 } |
1817 return 1; | 1818 return argskip + 1; |
1818 } | 1819 } |
1819 | 1820 |
1820 static void | 1821 static void |
1821 clear_submatch_list(staticList10_T *sl) | 1822 clear_submatch_list(staticList10_T *sl) |
1822 { | 1823 { |