vim-patch:9.0.1400: find_file_in_path() is not reentrant (#23146)

Problem:    find_file_in_path() is not reentrant.
Solution:   Instead of global variables pass pointers to the functions.
            (closes vim/vim#12093)

5145c9a829

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2023-04-17 14:38:53 +08:00
committed by GitHub
parent 85bc9e8970
commit 9722b3b9f9
4 changed files with 94 additions and 65 deletions

View File

@@ -2146,6 +2146,9 @@ static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what)
}
if (*fname != NUL && !error) {
char *file_to_find = NULL;
char *search_ctx = NULL;
do {
if (rettv->v_type == VAR_STRING || rettv->v_type == VAR_LIST) {
xfree(fresult);
@@ -2156,13 +2159,17 @@ static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what)
find_what, curbuf->b_ffname,
(find_what == FINDFILE_DIR
? ""
: curbuf->b_p_sua));
: curbuf->b_p_sua),
&file_to_find, &search_ctx);
first = false;
if (fresult != NULL && rettv->v_type == VAR_LIST) {
tv_list_append_string(rettv->vval.v_list, fresult, -1);
}
} while ((rettv->v_type == VAR_LIST || --count > 0) && fresult != NULL);
xfree(file_to_find);
vim_findfile_cleanup(search_ctx);
}
if (rettv->v_type == VAR_STRING) {