diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-03-18 00:47:46 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-04-13 12:00:31 -0400 |
commit | dbb386e1b277004e37902fd1c794727277312765 (patch) | |
tree | 856b1b4ab481bcaf624cf3e73393d9f97d0b869f /src/nvim/regexp.c | |
parent | 60a7184185a5656f723f17ab3d09157813baae13 (diff) | |
download | rneovim-dbb386e1b277004e37902fd1c794727277312765.tar.gz rneovim-dbb386e1b277004e37902fd1c794727277312765.tar.bz2 rneovim-dbb386e1b277004e37902fd1c794727277312765.zip |
vim-patch:8.1.2280: crash when passing partial to substitute()
Problem: Crash when passing partial to substitute().
Solution: Take extra arguments into account. (closes vim/vim#5186)
https://github.com/vim/vim/commit/b0745b221d284e381f1bd4b591cd68ea54b6a51d
Diffstat (limited to 'src/nvim/regexp.c')
-rw-r--r-- | src/nvim/regexp.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 90dc8ab90f..dba7c53c10 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -6491,20 +6491,24 @@ typedef struct { static regsubmatch_T rsm; // can only be used when can_f_submatch is true -/// Put the submatches in "argv[0]" which is a list passed into call_func() by -/// vim_regsub_both(). -static int fill_submatch_list(int argc, typval_T *argv, int argcount) +/// Put the submatches in "argv[argskip]" which is a list passed into +/// call_func() by vim_regsub_both(). +static int fill_submatch_list(int argc FUNC_ATTR_UNUSED, typval_T *argv, + int argskip, int argcount) + FUNC_ATTR_NONNULL_ALL { - if (argcount == 0) { - // called function doesn't take an argument - return 0; + typval_T *listarg = argv + argskip; + + if (argcount == argskip) { + // called function doesn't take a submatches argument + return argskip; } // Relies on sl_list to be the first item in staticList10_T. - tv_list_init_static10((staticList10_T *)argv->vval.v_list); + tv_list_init_static10((staticList10_T *)listarg->vval.v_list); // There are always 10 list items in staticList10_T. - listitem_T *li = tv_list_first(argv->vval.v_list); + listitem_T *li = tv_list_first(listarg->vval.v_list); for (int i = 0; i < 10; i++) { char_u *s = rsm.sm_match->startp[i]; if (s == NULL || rsm.sm_match->endp[i] == NULL) { @@ -6516,7 +6520,7 @@ static int fill_submatch_list(int argc, typval_T *argv, int argcount) TV_LIST_ITEM_TV(li)->vval.v_string = s; li = TV_LIST_ITEM_NEXT(argv->vval.v_list, li); } - return 1; + return argskip + 1; } static void clear_submatch_list(staticList10_T *sl) |