diff options
author | Matthieu Coudron <mattator@gmail.com> | 2020-04-13 22:49:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-13 22:49:00 +0200 |
commit | 93b2cb7a3824f91ee24ddf57406d5682699f684b (patch) | |
tree | 4ea7bb4aca7520a26a749b0958046ba52b450d4f /src/nvim/regexp.c | |
parent | 13b4a6fd4fa67794e76892cb362121a33a756f58 (diff) | |
parent | cf223e7d78df5e8a63b84d423be55a29eefd8883 (diff) | |
download | rneovim-93b2cb7a3824f91ee24ddf57406d5682699f684b.tar.gz rneovim-93b2cb7a3824f91ee24ddf57406d5682699f684b.tar.bz2 rneovim-93b2cb7a3824f91ee24ddf57406d5682699f684b.zip |
Merge pull request #11997 from janlazo/vim-8.1.2389
[RDY]vim-patch:8.1.{1745,2147,2280,2282,},8.2.{41,134,365,366,381,387,389,397,398,406,415,457,464,473,474,507,544,549}
Diffstat (limited to 'src/nvim/regexp.c')
-rw-r--r-- | src/nvim/regexp.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 90dc8ab90f..5ad7ce9a16 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) @@ -6679,10 +6683,15 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, // fill_submatch_list() was called. clear_submatch_list(&matchList); } - char buf[NUMBUFLEN]; - eval_result = (char_u *)tv_get_string_buf_chk(&rettv, buf); - if (eval_result != NULL) { - eval_result = vim_strsave(eval_result); + if (rettv.v_type == VAR_UNKNOWN) { + // something failed, no need to report another error + eval_result = NULL; + } else { + char buf[NUMBUFLEN]; + eval_result = (char_u *)tv_get_string_buf_chk(&rettv, buf); + if (eval_result != NULL) { + eval_result = vim_strsave(eval_result); + } } tv_clear(&rettv); } else { |