diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-21 07:08:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-21 07:08:09 +0800 |
commit | 76d35a5a3676630b64611b7c15c3c1c038864340 (patch) | |
tree | 30e073c1bce6d2c942cd0fb83236be177c9c29f4 /src | |
parent | 0d0a336c5348c653376766d90a86f187167ae5c5 (diff) | |
download | rneovim-76d35a5a3676630b64611b7c15c3c1c038864340.tar.gz rneovim-76d35a5a3676630b64611b7c15c3c1c038864340.tar.bz2 rneovim-76d35a5a3676630b64611b7c15c3c1c038864340.zip |
vim-patch:9.0.0231: expanding "**" may loop forever with directory links (#19866)
Problem: Expanding "**" may loop forever with directory links.
Solution: Check for being interrupted. (closes vim/vim#10946)
https://github.com/vim/vim/commit/57e95179abdd851cb2d0c06d4f973575a768e3bb
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/cmdexpand.c | 5 | ||||
-rw-r--r-- | src/nvim/path.c | 15 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index bf2ae1e16f..fee86ba43b 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -456,9 +456,10 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode findex = -1; // next p_wc gets first one } - // Concatenate all matching names + // Concatenate all matching names. Unless interrupted, this can be slow + // and the result probably won't be used. // TODO(philix): use xstpcpy instead of strcat in a loop (ExpandOne) - if (mode == WILD_ALL && xp->xp_numfiles > 0) { + if (mode == WILD_ALL && xp->xp_numfiles > 0 && !got_int) { size_t len = 0; for (i = 0; i < xp->xp_numfiles; i++) { len += STRLEN(xp->xp_files[i]) + 1; diff --git a/src/nvim/path.c b/src/nvim/path.c index a581f4fa6d..1500254de5 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -725,7 +725,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, // Find all matching entries. char_u *name; scandir_next_with_dots(NULL); // initialize - while ((name = (char_u *)scandir_next_with_dots(&dir)) != NULL) { + while (!got_int && (name = (char_u *)scandir_next_with_dots(&dir)) != NULL) { if ((name[0] != '.' || starts_with_dot || ((flags & EW_DODOT) @@ -774,8 +774,10 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff, xfree(buf); vim_regfree(regmatch.regprog); + // When interrupted the matches probably won't be used and sorting can be + // slow, thus skip it. size_t matches = (size_t)(gap->ga_len - start_len); - if (matches > 0) { + if (matches > 0 && !got_int) { qsort(((char_u **)gap->ga_data) + start_len, matches, sizeof(char_u *), pstrcmp); } @@ -1254,7 +1256,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i */ ga_init(&ga, (int)sizeof(char_u *), 30); - for (int i = 0; i < num_pat; ++i) { + for (int i = 0; i < num_pat && !got_int; i++) { add_pat = -1; p = (char_u *)pat[i]; @@ -2205,17 +2207,14 @@ int expand_wildcards(int num_pat, char **pat, int *num_files, char ***files, int } } - // // Move the names where 'suffixes' match to the end. - // + // Skip when interrupted, the result probably won't be used. assert(*num_files == 0 || *files != NULL); - if (*num_files > 1) { + if (*num_files > 1 && !got_int) { non_suf_match = 0; for (i = 0; i < *num_files; i++) { if (!match_suffix((char_u *)(*files)[i])) { - // // Move the name without matching suffix to the front of the list. - // p = (char_u *)(*files)[i]; for (j = i; j > non_suf_match; j--) { (*files)[j] = (*files)[j - 1]; |