aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-07-12 07:10:31 +0800
committerGitHub <noreply@github.com>2024-07-12 07:10:31 +0800
commita5de650f0eb93a848831f1ba631485437a82d57b (patch)
treeb56e10b64b915ce45c665a682667daba447ab1b7 /src
parent31d53cbb0fff48488f45ba234b8d595c31507739 (diff)
parent80818641f3504eb57a4fae5003f234f5f5f19ba1 (diff)
downloadrneovim-a5de650f0eb93a848831f1ba631485437a82d57b.tar.gz
rneovim-a5de650f0eb93a848831f1ba631485437a82d57b.tar.bz2
rneovim-a5de650f0eb93a848831f1ba631485437a82d57b.zip
Merge pull request #29668 from zeertzjq/vim-9.1.0562
vim-patch:9.1.{0562,0565,0566,0567}: file search fixes
Diffstat (limited to 'src')
-rw-r--r--src/nvim/file_search.c52
-rw-r--r--src/nvim/tag.c4
2 files changed, 29 insertions, 27 deletions
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index b6a039af5e..5760fc864a 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -349,23 +349,24 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char *));
do {
- char *helper;
- void *ptr;
-
- helper = walker;
- ptr = xrealloc(search_ctx->ffsc_stopdirs_v,
- (dircount + 1) * sizeof(char *));
+ char *helper = walker;
+ void *ptr = xrealloc(search_ctx->ffsc_stopdirs_v,
+ (dircount + 1) * sizeof(char *));
search_ctx->ffsc_stopdirs_v = ptr;
walker = vim_strchr(walker, ';');
+ assert(!walker || walker - helper >= 0);
+ size_t len = walker ? (size_t)(walker - helper) : strlen(helper);
+ // "" means ascent till top of directory tree.
+ if (*helper != NUL && !vim_isAbsName(helper) && len + 1 < MAXPATHL) {
+ // Make the stop dir an absolute path name.
+ xmemcpyz(ff_expand_buffer, helper, len);
+ search_ctx->ffsc_stopdirs_v[dircount - 1] = FullName_save(helper, len);
+ } else {
+ search_ctx->ffsc_stopdirs_v[dircount - 1] = xmemdupz(helper, len);
+ }
if (walker) {
- assert(walker - helper >= 0);
- search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrnsave(helper, (size_t)(walker - helper));
walker++;
- } else {
- // this might be "", which means ascent till top of directory tree.
- search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrdup(helper);
}
-
dircount++;
} while (walker != NULL);
search_ctx->ffsc_stopdirs_v[dircount - 1] = NULL;
@@ -892,11 +893,12 @@ char *vim_findfile(void *search_ctx_arg)
if (search_ctx->ffsc_start_dir
&& search_ctx->ffsc_stopdirs_v != NULL && !got_int) {
ff_stack_T *sptr;
+ // path_end may point to the NUL or the previous path separator
+ ptrdiff_t plen = (path_end - search_ctx->ffsc_start_dir) + (*path_end != NUL);
// is the last starting directory in the stop list?
if (ff_path_in_stoplist(search_ctx->ffsc_start_dir,
- (int)(path_end - search_ctx->ffsc_start_dir),
- search_ctx->ffsc_stopdirs_v)) {
+ (size_t)plen, search_ctx->ffsc_stopdirs_v)) {
break;
}
@@ -1231,7 +1233,7 @@ static void ff_clear(ff_search_ctx_T *search_ctx)
/// check if the given path is in the stopdirs
///
/// @return true if yes else false
-static bool ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v)
+static bool ff_path_in_stoplist(char *path, size_t path_len, char **stopdirs_v)
{
// eat up trailing path separators, except the first
while (path_len > 1 && vim_ispathsep(path[path_len - 1])) {
@@ -1244,20 +1246,16 @@ static bool ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v)
}
for (int i = 0; stopdirs_v[i] != NULL; i++) {
- if ((int)strlen(stopdirs_v[i]) > path_len) {
- // match for parent directory. So '/home' also matches
- // '/home/rks'. Check for PATHSEP in stopdirs_v[i], else
- // '/home/r' would also match '/home/rks'
- if (path_fnamencmp(stopdirs_v[i], path, (size_t)path_len) == 0
- && vim_ispathsep(stopdirs_v[i][path_len])) {
- return true;
- }
- } else {
- if (path_fnamecmp(stopdirs_v[i], path) == 0) {
- return true;
- }
+ // match for parent directory. So '/home' also matches
+ // '/home/rks'. Check for PATHSEP in stopdirs_v[i], else
+ // '/home/r' would also match '/home/rks'
+ if (path_fnamencmp(stopdirs_v[i], path, path_len) == 0
+ && (strlen(stopdirs_v[i]) <= path_len
+ || vim_ispathsep(stopdirs_v[i][path_len]))) {
+ return true;
}
}
+
return false;
}
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index 90269c776e..cc7ff070c2 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -2583,6 +2583,10 @@ int get_tagfname(tagname_T *tnp, int first, char *buf)
// move the filename one char forward and truncate the
// filepath with a NUL
filename = path_tail(buf);
+ if (r_ptr != NULL) {
+ STRMOVE(r_ptr + 1, r_ptr);
+ r_ptr++;
+ }
STRMOVE(filename + 1, filename);
*filename++ = NUL;