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)
57e95179ab
This commit is contained in:
zeertzjq
2022-08-21 07:08:09 +08:00
committed by GitHub
parent 0d0a336c53
commit 76d35a5a36
2 changed files with 10 additions and 10 deletions

View File

@@ -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;

View File

@@ -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];