From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/path.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index e4c2253357..9bbf56276e 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -810,7 +810,7 @@ static int find_previous_pathsep(char *path, char **psep) } /// Returns true if "maybe_unique" is unique wrt other_paths in "gap". -/// "maybe_unique" is the end portion of "((char_u **)gap->ga_data)[i]". +/// "maybe_unique" is the end portion of "((char **)gap->ga_data)[i]". static bool is_unique(char *maybe_unique, garray_T *gap, int i) { char **other_paths = gap->ga_data; @@ -879,7 +879,7 @@ static void expand_path_option(char *curdir, garray_T *gap) } STRMOVE(buf + len + 1, buf); STRCPY(buf, curdir); - buf[len] = (char_u)PATHSEP; + buf[len] = PATHSEP; simplify_filename(buf); } @@ -1923,7 +1923,7 @@ void path_fix_case(char *name) xstrlcpy(newname + (tail - name), entry, (size_t)(MAXPATHL - (tail - name) + 1)); FileInfo file_info_new; - if (os_fileinfo_link((char *)newname, &file_info_new) + if (os_fileinfo_link(newname, &file_info_new) && os_fileinfo_id_equal(&file_info, &file_info_new)) { STRCPY(tail, entry); break; @@ -1956,11 +1956,11 @@ bool same_directory(char *f1, char *f2) return false; } - (void)vim_FullName(f1, (char *)ffname, MAXPATHL, false); + (void)vim_FullName(f1, ffname, MAXPATHL, false); t1 = path_tail_with_sep(ffname); t2 = path_tail_with_sep(f2); return t1 - ffname == t2 - f2 - && pathcmp((char *)ffname, f2, (int)(t1 - ffname)) == 0; + && pathcmp(ffname, f2, (int)(t1 - ffname)) == 0; } // Compare path "p[]" to "q[]". -- cgit From 063e93864a7e99ac1c4781bbe4ea63c0adb075a8 Mon Sep 17 00:00:00 2001 From: Lucas Merritt Date: Fri, 24 Mar 2023 22:11:14 -0600 Subject: refactor(PVS/V1048): remove duplicated assignments (#21873) --- src/nvim/path.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 9bbf56276e..973e5eaec4 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2375,7 +2375,6 @@ static int path_to_absolute(const char *fname, char *buf, size_t len, int force) end_of_path = p + 1; } else { relative_directory[0] = NUL; - end_of_path = (char *)fname; } if (FAIL == path_full_dir_name(relative_directory, buf, len)) { -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 973e5eaec4..e68a06821a 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -973,7 +973,7 @@ static void uniquefy_paths(garray_T *gap, char *pattern) for (int i = 0; i < gap->ga_len && !got_int; i++) { char *path = fnames[i]; int is_in_curdir; - char *dir_end = (char *)gettail_dir((const char *)path); + char *dir_end = (char *)gettail_dir(path); char *pathsep_p; char *path_cutoff; -- cgit From 04933b1ea968f958d2541dd65fd33ebb503caac3 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:08:16 +0200 Subject: refactor: remove redundant casts --- src/nvim/path.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index e68a06821a..f320ecb342 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -656,7 +656,7 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in )) { // NOLINT(whitespace/parens) e = p; } - len = (size_t)(utfc_ptr2len((char *)path_end)); + len = (size_t)(utfc_ptr2len(path_end)); memcpy(p, path_end, len); p += len; path_end += len; @@ -973,7 +973,7 @@ static void uniquefy_paths(garray_T *gap, char *pattern) for (int i = 0; i < gap->ga_len && !got_int; i++) { char *path = fnames[i]; int is_in_curdir; - char *dir_end = (char *)gettail_dir(path); + const char *dir_end = gettail_dir(path); char *pathsep_p; char *path_cutoff; @@ -1911,8 +1911,8 @@ void path_fix_case(char *name) return; } - char *entry; - while ((entry = (char *)os_scandir_next(&dir))) { + const char *entry; + while ((entry = os_scandir_next(&dir))) { // Only accept names that differ in case and are the same byte // length. TODO: accept different length name. if (STRICMP(tail, entry) == 0 && strlen(tail) == strlen(entry)) { @@ -2021,7 +2021,7 @@ int pathcmp(const char *p, const char *q, int maxlen) // ignore a trailing slash, but not "//" or ":/" if (c2 == NUL && i > 0 - && !after_pathsep((char *)s, (char *)s + i) + && !after_pathsep(s, s + i) #ifdef BACKSLASH_IN_FILENAME && (c1 == '/' || c1 == '\\') #else @@ -2354,11 +2354,11 @@ int append_path(char *path, const char *to_append, size_t max_len) /// @return FAIL for failure, OK for success. static int path_to_absolute(const char *fname, char *buf, size_t len, int force) { - char *p; + const char *p; *buf = NUL; char *relative_directory = xmalloc(len); - char *end_of_path = (char *)fname; + const char *end_of_path = fname; // expand it if forced or not an absolute path if (force || !path_is_absolute(fname)) { -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/path.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index f320ecb342..368f3feb27 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -641,7 +641,7 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in while (*path_end != NUL) { // May ignore a wildcard that has a backslash before it; it will // be removed by rem_backslash() or file_pat_to_reg_pat() below. - if (path_end >= path + wildoff && rem_backslash((char *)path_end)) { + if (path_end >= path + wildoff && rem_backslash(path_end)) { *p++ = *path_end++; } else if (vim_ispathsep_nocolon(*path_end)) { if (e != NULL) { @@ -651,7 +651,7 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in } else if (path_end >= path + wildoff && (vim_strchr("*?[{~$", (uint8_t)(*path_end)) != NULL #ifndef MSWIN - || (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char((char *)path_end))) + || (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char(path_end))) #endif )) { // NOLINT(whitespace/parens) e = p; @@ -727,9 +727,9 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in char *dirpath = (*buf == NUL ? "." : buf); if (os_file_is_readable(dirpath) && os_scandir(&dir, dirpath)) { // Find all matching entries. - char *name; + const char *name; scandir_next_with_dots(NULL); // initialize - while (!got_int && (name = (char *)scandir_next_with_dots(&dir)) != NULL) { + while (!got_int && (name = scandir_next_with_dots(&dir)) != NULL) { if ((name[0] != '.' || starts_with_dot || ((flags & EW_DODOT) -- cgit From 8e2903d2fe810cfa3be41fc1e7a4d8394c84cf11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 09:11:37 +0800 Subject: vim-patch:8.2.1049: Vim9: leaking memory when using continuation line Problem: Vim9: leaking memory when using continuation line. Solution: Keep a pointer to the continuation line in evalarg_T. Centralize checking for a next command. https://github.com/vim/vim/commit/b171fb179053fa631fec74911b5fb9374cb6a8a1 Omit eval_next_line(): Vim9 script only. vim-patch:8.2.1050: missing change in struct Problem: Missing change in struct. Solution: Add missing change. https://github.com/vim/vim/commit/65a8ed37f7bc61fbe5c612a7b0eb0dfc16ad3e11 Co-authored-by: Bram Moolenaar --- src/nvim/path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 368f3feb27..8bd3303166 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1371,7 +1371,7 @@ static int expand_backtick(garray_T *gap, char *pat, int flags) char *cmd = xstrnsave(pat + 1, strlen(pat) - 2); if (*cmd == '=') { // `={expr}`: Expand expression - buffer = eval_to_string(cmd + 1, &p, true); + buffer = eval_to_string(cmd + 1, true); } else { buffer = get_cmd_output(cmd, NULL, (flags & EW_SILENT) ? kShellOptSilent : 0, NULL); } @@ -1662,7 +1662,7 @@ void simplify_filename(char *filename) static char *eval_includeexpr(const char *const ptr, const size_t len) { set_vim_var_string(VV_FNAME, ptr, (ptrdiff_t)len); - char *res = eval_to_string_safe(curbuf->b_p_inex, NULL, + char *res = eval_to_string_safe(curbuf->b_p_inex, was_set_insecurely(curwin, "includeexpr", OPT_LOCAL)); set_vim_var_string(VV_FNAME, NULL, 0); return res; -- cgit From 9722b3b9f983a3401423c41f05dd559f6aa410cd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Apr 2023 14:38:53 +0800 Subject: 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) https://github.com/vim/vim/commit/5145c9a829cd43cb9e7962b181bf99226eb3a53f Co-authored-by: Bram Moolenaar --- src/nvim/path.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 8bd3303166..137a8da2bc 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1690,8 +1690,11 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha } if (options & FNAME_EXP) { - file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, true, - rel_fname); + char *file_to_find = NULL; + char *search_ctx = NULL; + + file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, + true, rel_fname, &file_to_find, &search_ctx); // If the file could not be found in a normal way, try applying // 'includeexpr' (unless done already). @@ -1702,7 +1705,7 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha ptr = tofree; len = strlen(ptr); file_name = find_file_in_path(ptr, len, options & ~FNAME_MESS, - true, rel_fname); + true, rel_fname, &file_to_find, &search_ctx); } } if (file_name == NULL && (options & FNAME_MESS)) { @@ -1716,9 +1719,12 @@ char *find_file_name_in_path(char *ptr, size_t len, int options, long count, cha // appears several times in the path. while (file_name != NULL && --count > 0) { xfree(file_name); - file_name = - find_file_in_path(ptr, len, options, false, rel_fname); + file_name = find_file_in_path(ptr, len, options, false, rel_fname, + &file_to_find, &search_ctx); } + + xfree(file_to_find); + vim_findfile_cleanup(search_ctx); } else { file_name = xstrnsave(ptr, len); } -- cgit From 96451e7f606947c33b11ca024fa76dedf47314b1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Apr 2023 15:22:54 +0800 Subject: vim-patch:8.2.4184: cannot use an import in 'includeexpr' Problem: Cannot use an import in 'includeexpr'. Solution: Set the script context when evaluating 'includeexpr' https://github.com/vim/vim/commit/47bcc5f4c83c158f43ac2ea7abfe99dbf5c2e098 Co-authored-by: Bram Moolenaar --- src/nvim/path.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 137a8da2bc..cf7cd98829 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1661,10 +1661,15 @@ void simplify_filename(char *filename) static char *eval_includeexpr(const char *const ptr, const size_t len) { + const sctx_T save_sctx = current_sctx; set_vim_var_string(VV_FNAME, ptr, (ptrdiff_t)len); + current_sctx = curbuf->b_p_script_ctx[BV_INEX].script_ctx; + char *res = eval_to_string_safe(curbuf->b_p_inex, was_set_insecurely(curwin, "includeexpr", OPT_LOCAL)); + set_vim_var_string(VV_FNAME, NULL, 0); + current_sctx = save_sctx; return res; } -- cgit From aee6f08ce12a62e9104892702a658a8d3daee4df Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 17 Apr 2023 13:08:53 +0200 Subject: fix(runtime): do not allow breakcheck inside runtime path calculation problem: breakcheck might run arbitrary lua code, which might require modules and thus invoke runtime path calculation recursively. solution: Block the use of breakcheck when expanding glob patterns inside 'runtimepath' fixes #23012 --- src/nvim/path.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index cf7cd98829..21a3a67e24 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -620,7 +620,7 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in static int stardepth = 0; // depth for "**" expansion // Expanding "**" may take a long time, check for CTRL-C. - if (stardepth > 0) { + if (stardepth > 0 && !(flags & EW_NOBREAK)) { os_breakcheck(); if (got_int) { return 0; @@ -701,7 +701,8 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in if (flags & (EW_NOERROR | EW_NOTWILD)) { emsg_silent++; } - regmatch.regprog = vim_regcomp(pat, RE_MAGIC); + bool nobreak = (flags & EW_NOBREAK); + regmatch.regprog = vim_regcomp(pat, RE_MAGIC | (nobreak ? RE_NOBREAK : 0)); if (flags & (EW_NOERROR | EW_NOTWILD)) { emsg_silent--; } -- cgit From dd24ea819507e3a5da04df55df7dda5240e5b57f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 7 Jun 2023 09:29:12 +0800 Subject: fix(events): don't expand non-file as file name --- src/nvim/path.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 21a3a67e24..ea0d5a8be1 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2087,17 +2087,17 @@ char *path_shorten_fname(char *full_path, char *dir_name) assert(dir_name != NULL); size_t len = strlen(dir_name); - // If dir_name is a path head, full_path can always be made relative. - if (len == (size_t)path_head_length() && is_path_head(dir_name)) { - return full_path + len; - } - // If full_path and dir_name do not match, it's impossible to make one // relative to the other. if (path_fnamencmp(dir_name, full_path, len) != 0) { return NULL; } + // If dir_name is a path head, full_path can always be made relative. + if (len == (size_t)path_head_length() && is_path_head(dir_name)) { + return full_path + len; + } + char *p = full_path + len; // If *p is not pointing to a path separator, this means that full_path's -- cgit From aa362a2af8ce353d7082834a54bcc124ebd2a026 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 29 Jun 2023 15:48:42 +0800 Subject: refactor: remove some casts to char * (#24200) --- src/nvim/path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index ea0d5a8be1..0927a3a102 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1810,7 +1810,7 @@ bool path_with_extension(const char *path, const char *extension) } /// Return true if "name" is a full (absolute) path name or URL. -bool vim_isAbsName(char *name) +bool vim_isAbsName(const char *name) { return path_with_url(name) != 0 || path_is_absolute(name); } @@ -1871,7 +1871,7 @@ char *fix_fname(const char *fname) #ifdef UNIX return FullName_save(fname, true); #else - if (!vim_isAbsName((char *)fname) + if (!vim_isAbsName(fname) || strstr(fname, "..") != NULL || strstr(fname, "//") != NULL # ifdef BACKSLASH_IN_FILENAME -- cgit From a741c7fd0465c949a0016fcbee5f4526b65f8c02 Mon Sep 17 00:00:00 2001 From: Alexandre Teoi Date: Sat, 1 Jul 2023 10:33:51 -0300 Subject: fix(api): nvim_parse_cmd error message in pcall() #23297 Problem: nvim_parse_cmd() in pcall() may show an error message (side-effect): :lua pcall(vim.api.nvim_parse_cmd, vim.fn.getcmdline(), {}) E16: Invalid range Solution: Avoid emsg() in the nvim_parse_cmd() codepath. - refactor(api): add error message output parameter to get_address() - fix: null check emsg() parameter - refactor: remove emsg_off workaround from do_incsearch_highlighting() - refactor: remove emsg_off workaround from cmdpreview_may_show() - refactor: remove remaining calls to emsg() from parse_cmd_address() and get_address() - (refactor): lint set_cmd_dflall_range() - refactor: addr_error() - move output parameter to return value Fix #20339 TODO: These are the functions called by `get_address()`: ``` nvim_parse_cmd() -> parse_cmdline() -> parse_cmd_address() -> get_address() skipwhite() addr_error() qf_get_cur_idx() qf_get_cur_valid_idx() qf_get_size() qf_get_valid_size() mark_get() mark_check() assert() skip_regexp() magic_isset() > do_search() > searchit() ascii_isdigit() getdigits() getdigits_int32() compute_buffer_local_count() hasFolding() ``` From these functions, I found at least two that call emsg directly: - do_search() - seems to be simple to refactor - searchit() - will be more challenging because it may generate multiple error messages, which can't be handled by the current `errormsg` out-parameter. For example, it makes multiple calls to `vim_regexec_multi()` in a loop that possibly generate error messages, and later `searchit()` itself may generate another one: - https://github.com/neovim/neovim/blob/c194acbfc479d8e5839fa629363f93f6550d035c/src/nvim/search.c#L631-L647 - https://github.com/neovim/neovim/blob/c194acbfc479d8e5839fa629363f93f6550d035c/src/nvim/search.c#L939-L954 --------- Co-authored-by: Justin M. Keyes --- src/nvim/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 0927a3a102..b9ae756027 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2129,7 +2129,7 @@ int expand_wildcards_eval(char **pat, int *num_file, char ***file, int flags) int ret = FAIL; char *eval_pat = NULL; char *exp_pat = *pat; - char *ignored_msg; + const char *ignored_msg; size_t usedlen; const bool is_cur_alt_file = *exp_pat == '%' || *exp_pat == '#'; bool star_follows = false; -- cgit From fbeef0d4ef1aadc4e50b9f33946cf4dca8ca6b62 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 8 Jul 2023 23:29:24 +0800 Subject: fix(completion): don't add backslashes to runtime pattern (#24296) Problem: Bashslashes added as regexp in runtime completion may be treated as path separator with some 'isfname' value. Solution: Make curly braces work for runtime completion and use it. --- src/nvim/path.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index b9ae756027..828b690699 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1163,7 +1163,7 @@ static bool has_env_var(char *p) // Return true if "p" contains a special wildcard character, one that Vim // cannot expand, requires using a shell. -static bool has_special_wildchar(char *p) +static bool has_special_wildchar(char *p, int flags) { for (; *p; MB_PTR_ADV(p)) { // Disallow line break characters. @@ -1174,6 +1174,10 @@ static bool has_special_wildchar(char *p) if (*p == '\\' && p[1] != NUL && p[1] != '\r' && p[1] != '\n') { p++; } else if (vim_strchr(SPECIAL_WILDCHAR, (uint8_t)(*p)) != NULL) { + // Need a shell for curly braces only when including non-existing files. + if (*p == '{' && !(flags & EW_NOTFOUND)) { + continue; + } // A { must be followed by a matching }. if (*p == '{' && vim_strchr(p, '}') == NULL) { continue; @@ -1233,7 +1237,7 @@ int gen_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, i // avoids starting the shell for each argument separately. // For `=expr` do use the internal function. for (int i = 0; i < num_pat; i++) { - if (has_special_wildchar(pat[i]) + if (has_special_wildchar(pat[i], flags) && !(vim_backtick(pat[i]) && pat[i][1] == '=')) { return os_expand_wildcards(num_pat, pat, num_file, file, flags); } -- cgit From 9176b5e10a6b32ff65c8ba3f532e3bd55c168ec6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Jul 2023 07:57:13 +0800 Subject: fix(runtime): respect 'fileignorecase' when sourcing (#24344) --- src/nvim/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 828b690699..d1e0947038 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1810,7 +1810,7 @@ bool path_with_extension(const char *path, const char *extension) if (!last_dot) { return false; } - return strcmp(last_dot + 1, extension) == 0; + return mb_strcmp_ic((bool)p_fic, last_dot + 1, extension) == 0; } /// Return true if "name" is a full (absolute) path name or URL. -- cgit From 881d17a11393da75a27c072faa3fd45f510175fe Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Jul 2023 14:27:21 +0100 Subject: feat(options)!: remove compatible behaviours for vim 5.0 and earlier --- src/nvim/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index d1e0947038..3b36c2a550 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -847,7 +847,7 @@ static void expand_path_option(char *curdir, garray_T *gap) char *buf = xmalloc(MAXPATHL); while (*path_option != NUL) { - copy_option_part(&path_option, buf, MAXPATHL, " ,"); + copy_option_part(&path_option, buf, MAXPATHL, ","); if (buf[0] == '.' && (buf[1] == NUL || vim_ispathsep(buf[1]))) { // Relative to current buffer: -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/path.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 3b36c2a550..36bbe3836d 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -2,7 +2,6 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include -#include #include #include #include @@ -12,10 +11,10 @@ #include "auto/config.h" #include "nvim/ascii.h" -#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cmdexpand.h" #include "nvim/eval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/ex_docmd.h" #include "nvim/file_search.h" #include "nvim/fileio.h" @@ -35,7 +34,6 @@ #include "nvim/pos.h" #include "nvim/regexp.h" #include "nvim/strings.h" -#include "nvim/types.h" #include "nvim/vim.h" #include "nvim/window.h" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/path.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 36bbe3836d..21f0543756 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -26,6 +26,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/fs_defs.h" #include "nvim/os/input.h" #include "nvim/os/os.h" -- cgit From 1e7e9ee91f73c62b8c5ba9dbdabba3a3b6dc0130 Mon Sep 17 00:00:00 2001 From: Leonardo Mello Date: Tue, 3 Oct 2023 19:04:19 -0300 Subject: fix(path): accept special characters on Windows (#25424) --- src/nvim/path.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 21f0543756..5d991ce719 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -648,11 +648,13 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in } s = p + 1; } else if (path_end >= path + wildoff +#ifdef MSWIN + && vim_strchr("*?[~", (uint8_t)(*path_end)) != NULL +#else && (vim_strchr("*?[{~$", (uint8_t)(*path_end)) != NULL -#ifndef MSWIN - || (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char(path_end))) + || (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char(path_end)))) #endif - )) { // NOLINT(whitespace/parens) + ) { // NOLINT(whitespace/parens) e = p; } len = (size_t)(utfc_ptr2len(path_end)); -- cgit From f5eabaa9407ae3d1ccf6592337453c423eff3d9a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 10 Oct 2023 08:22:32 +0800 Subject: fix(path): restore space separation in 'path' (#25571) Removing this behavior causes more inconsistencies and bugs. --- src/nvim/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 5d991ce719..15a8762da1 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -848,7 +848,7 @@ static void expand_path_option(char *curdir, garray_T *gap) char *buf = xmalloc(MAXPATHL); while (*path_option != NUL) { - copy_option_part(&path_option, buf, MAXPATHL, ","); + copy_option_part(&path_option, buf, MAXPATHL, " ,"); if (buf[0] == '.' && (buf[1] == NUL || vim_ispathsep(buf[1]))) { // Relative to current buffer: -- cgit From cd63a9addd6e1114c3524fa041ece560550cfe7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 08:39:21 +0800 Subject: refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959) When the given length is exactly the number of bytes to copy, xmemdupz() makes the intention clearer. --- src/nvim/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 15a8762da1..8cc824337c 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1374,7 +1374,7 @@ static int expand_backtick(garray_T *gap, char *pat, int flags) int cnt = 0; // Create the command: lop off the backticks. - char *cmd = xstrnsave(pat + 1, strlen(pat) - 2); + char *cmd = xmemdupz(pat + 1, strlen(pat) - 2); if (*cmd == '=') { // `={expr}`: Expand expression buffer = eval_to_string(cmd + 1, true); -- cgit From 8e58d37f2e15ac8540377148e55ed08a039aadb6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 11 Nov 2023 11:20:08 +0100 Subject: refactor: remove redundant casts --- src/nvim/path.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 8cc824337c..f552f24495 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -995,7 +995,7 @@ static void uniquefy_paths(garray_T *gap, char *pattern) if (pattern[0] == '*' && pattern[1] == '*' && vim_ispathsep_nocolon(pattern[2]) && path_cutoff != NULL - && vim_regexec(®match, path_cutoff, (colnr_T)0) + && vim_regexec(®match, path_cutoff, 0) && is_unique(path_cutoff, gap, i)) { sort_again = true; memmove(path, path_cutoff, strlen(path_cutoff) + 1); @@ -1004,7 +1004,7 @@ static void uniquefy_paths(garray_T *gap, char *pattern) // unique path. We start at the end of the path. */ pathsep_p = path + len - 1; while (find_previous_pathsep(path, &pathsep_p)) { - if (vim_regexec(®match, pathsep_p + 1, (colnr_T)0) + if (vim_regexec(®match, pathsep_p + 1, 0) && is_unique(pathsep_p + 1, gap, i) && path_cutoff != NULL && pathsep_p + 1 >= path_cutoff) { sort_again = true; -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/path.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index f552f24495..d08866ed14 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include @@ -736,7 +733,7 @@ static size_t do_path_expand(garray_T *gap, const char *path, size_t wildoff, in || starts_with_dot || ((flags & EW_DODOT) && name[1] != NUL - && (name[1] != '.' || name[2] != NUL))) // -V557 + && (name[1] != '.' || name[2] != NUL))) && ((regmatch.regprog != NULL && vim_regexec(®match, name, 0)) || ((flags & EW_NOTWILD) && path_fnamencmp(path + (s - buf), name, (size_t)(e - s)) == 0))) { -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/path.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index d08866ed14..dc7e0d9645 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1554,14 +1554,13 @@ void simplify_filename(char *filename) if (components > 0) { // strip one preceding component bool do_strip = false; - char saved_char; // Don't strip for an erroneous file name. if (!stripping_disabled) { // If the preceding component does not exist in the file // system, we strip it. On Unix, we don't accept a symbolic // link that refers to a non-existent file. - saved_char = p[-1]; + char saved_char = p[-1]; p[-1] = NUL; FileInfo file_info; if (!os_fileinfo_link(filename, &file_info)) { @@ -2186,12 +2185,7 @@ int expand_wildcards_eval(char **pat, int *num_file, char ***file, int flags) /// NULL or points to "". int expand_wildcards(int num_pat, char **pat, int *num_files, char ***files, int flags) { - int retval; - int i, j; - char *p; - int non_suf_match; // number without matching suffix - - retval = gen_expand_wildcards(num_pat, pat, num_files, files, flags); + int retval = gen_expand_wildcards(num_pat, pat, num_files, files, flags); // When keeping all matches, return here if ((flags & EW_KEEPALL) || retval == FAIL) { @@ -2200,18 +2194,16 @@ int expand_wildcards(int num_pat, char **pat, int *num_files, char ***files, int // Remove names that match 'wildignore'. if (*p_wig) { - char *ffname; - // check all files in (*files)[] assert(*num_files == 0 || *files != NULL); - for (i = 0; i < *num_files; i++) { - ffname = FullName_save((*files)[i], false); + for (int i = 0; i < *num_files; i++) { + char *ffname = FullName_save((*files)[i], false); assert((*files)[i] != NULL); assert(ffname != NULL); if (match_file_list(p_wig, (*files)[i], ffname)) { // remove this matching file from the list xfree((*files)[i]); - for (j = i; j + 1 < *num_files; j++) { + for (int j = i; j + 1 < *num_files; j++) { (*files)[j] = (*files)[j + 1]; } (*num_files)--; @@ -2225,12 +2217,12 @@ int expand_wildcards(int num_pat, char **pat, int *num_files, char ***files, int // Skip when interrupted, the result probably won't be used. assert(*num_files == 0 || *files != NULL); if (*num_files > 1 && !got_int) { - non_suf_match = 0; - for (i = 0; i < *num_files; i++) { + int non_suf_match = 0; // number without matching suffix + for (int i = 0; i < *num_files; i++) { if (!match_suffix((*files)[i])) { // Move the name without matching suffix to the front of the list. - p = (*files)[i]; - for (j = i; j > non_suf_match; j--) { + char *p = (*files)[i]; + for (int j = i; j > non_suf_match; j--) { (*files)[j] = (*files)[j - 1]; } (*files)[non_suf_match++] = p; -- cgit From bb4b4576e384c71890b4df4fa4f1ae76fad3a59d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Nov 2023 10:55:54 +0800 Subject: refactor: iwyu (#26062) --- src/nvim/path.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index dc7e0d9645..1cd663bde4 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -29,7 +29,6 @@ #include "nvim/os/os.h" #include "nvim/os/shell.h" #include "nvim/path.h" -#include "nvim/pos.h" #include "nvim/regexp.h" #include "nvim/strings.h" #include "nvim/vim.h" -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/path.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 1cd663bde4..8ffa334370 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1500,11 +1500,10 @@ void addfile(garray_T *gap, char *f, int flags) void simplify_filename(char *filename) { int components = 0; - char *p, *tail, *start; bool stripping_disabled = false; bool relative = true; - p = filename; + char *p = filename; #ifdef BACKSLASH_IN_FILENAME if (p[0] != NUL && p[1] == ':') { // skip "x:" p += 2; @@ -1517,7 +1516,7 @@ void simplify_filename(char *filename) p++; } while (vim_ispathsep(*p)); } - start = p; // remember start after "c:/" or "/" or "///" + char *start = p; // remember start after "c:/" or "/" or "///" do { // At this point "p" is pointing to the char following a single "/" @@ -1533,7 +1532,7 @@ void simplify_filename(char *filename) // and there is no trailing path separator, either strip "/." if // we are after "start", or strip "." if we are at the beginning // of an absolute path name. - tail = p + 1; + char *tail = p + 1; if (p[1] != NUL) { while (vim_ispathsep(*tail)) { MB_PTR_ADV(tail); @@ -1546,7 +1545,7 @@ void simplify_filename(char *filename) } else if (p[0] == '.' && p[1] == '.' && (vim_ispathsep(p[2]) || p[2] == NUL)) { // Skip to after ".." or "../" or "..///". - tail = p + 2; + char *tail = p + 2; while (vim_ispathsep(*tail)) { MB_PTR_ADV(tail); } @@ -1981,12 +1980,11 @@ bool same_directory(char *f1, char *f2) int pathcmp(const char *p, const char *q, int maxlen) { int i, j; - int c1, c2; const char *s = NULL; for (i = 0, j = 0; maxlen < 0 || (i < maxlen && j < maxlen);) { - c1 = utf_ptr2char(p + i); - c2 = utf_ptr2char(q + j); + int c1 = utf_ptr2char(p + i); + int c2 = utf_ptr2char(q + j); // End of "p": check if "q" also ends or just has a slash. if (c1 == NUL) { @@ -2028,8 +2026,8 @@ int pathcmp(const char *p, const char *q, int maxlen) return 0; } - c1 = utf_ptr2char(s + i); - c2 = utf_ptr2char(s + i + utfc_ptr2len(s + i)); + int c1 = utf_ptr2char(s + i); + int c2 = utf_ptr2char(s + i + utfc_ptr2len(s + i)); // ignore a trailing slash, but not "//" or ":/" if (c2 == NUL && i > 0 -- cgit From 6361806aa28edca55ad3316a58bc3e936df9c0eb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Nov 2023 22:58:52 +0800 Subject: refactor: move garray_T to garray_defs.h (#26227) --- src/nvim/path.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 8ffa334370..ad1d8771aa 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -16,6 +16,7 @@ #include "nvim/file_search.h" #include "nvim/fileio.h" #include "nvim/garray.h" +#include "nvim/garray_defs.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/macros.h" -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index ad1d8771aa..805b361bb1 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -25,7 +25,7 @@ #include "nvim/message.h" #include "nvim/option.h" #include "nvim/option_vars.h" -#include "nvim/os/fs_defs.h" +#include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/shell.h" -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/path.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index 805b361bb1..c7ec8eccd6 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -15,6 +15,7 @@ #include "nvim/ex_docmd.h" #include "nvim/file_search.h" #include "nvim/fileio.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/garray_defs.h" #include "nvim/gettext.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/path.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/path.c') diff --git a/src/nvim/path.c b/src/nvim/path.c index c7ec8eccd6..c7212c7ade 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -7,7 +7,7 @@ #include #include "auto/config.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/charset.h" #include "nvim/cmdexpand.h" #include "nvim/eval.h" @@ -20,7 +20,7 @@ #include "nvim/garray_defs.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/message.h" @@ -33,7 +33,7 @@ #include "nvim/path.h" #include "nvim/regexp.h" #include "nvim/strings.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" enum { -- cgit