mirror of
https://github.com/neovim/neovim.git
synced 2025-09-21 02:38:19 +00:00
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:
@@ -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
|
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)
|
// 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;
|
size_t len = 0;
|
||||||
for (i = 0; i < xp->xp_numfiles; i++) {
|
for (i = 0; i < xp->xp_numfiles; i++) {
|
||||||
len += STRLEN(xp->xp_files[i]) + 1;
|
len += STRLEN(xp->xp_files[i]) + 1;
|
||||||
|
@@ -725,7 +725,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff,
|
|||||||
// Find all matching entries.
|
// Find all matching entries.
|
||||||
char_u *name;
|
char_u *name;
|
||||||
scandir_next_with_dots(NULL); // initialize
|
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] != '.'
|
if ((name[0] != '.'
|
||||||
|| starts_with_dot
|
|| starts_with_dot
|
||||||
|| ((flags & EW_DODOT)
|
|| ((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);
|
xfree(buf);
|
||||||
vim_regfree(regmatch.regprog);
|
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);
|
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,
|
qsort(((char_u **)gap->ga_data) + start_len, matches,
|
||||||
sizeof(char_u *), pstrcmp);
|
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);
|
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;
|
add_pat = -1;
|
||||||
p = (char_u *)pat[i];
|
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.
|
// 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);
|
assert(*num_files == 0 || *files != NULL);
|
||||||
if (*num_files > 1) {
|
if (*num_files > 1 && !got_int) {
|
||||||
non_suf_match = 0;
|
non_suf_match = 0;
|
||||||
for (i = 0; i < *num_files; i++) {
|
for (i = 0; i < *num_files; i++) {
|
||||||
if (!match_suffix((char_u *)(*files)[i])) {
|
if (!match_suffix((char_u *)(*files)[i])) {
|
||||||
//
|
|
||||||
// Move the name without matching suffix to the front of the list.
|
// Move the name without matching suffix to the front of the list.
|
||||||
//
|
|
||||||
p = (char_u *)(*files)[i];
|
p = (char_u *)(*files)[i];
|
||||||
for (j = i; j > non_suf_match; j--) {
|
for (j = i; j > non_suf_match; j--) {
|
||||||
(*files)[j] = (*files)[j - 1];
|
(*files)[j] = (*files)[j - 1];
|
||||||
|
Reference in New Issue
Block a user