diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-01-24 08:52:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-24 00:52:55 +0000 |
commit | 2470db02c5136525b8abce1ee0889d94f8d81d98 (patch) | |
tree | 07418e7e683c431f1e39a76c875fa53273d5410e /src/nvim/path.c | |
parent | 8bc28978b632362ae658f8d4a6327e07a8b371b2 (diff) | |
download | rneovim-2470db02c5136525b8abce1ee0889d94f8d81d98.tar.gz rneovim-2470db02c5136525b8abce1ee0889d94f8d81d98.tar.bz2 rneovim-2470db02c5136525b8abce1ee0889d94f8d81d98.zip |
vim-patch:partial:9.1.1050: too many strlen() calls in os_unix.c (#32188)
Problem: too many strlen() calls in os_unix.c
Solution: refactor os_unix.c and remove calls to strlen()
(John Marriott)
closes: vim/vim#16496
https://github.com/vim/vim/commit/efc41a5958bf25b352e0916af5f57dafbbb44f17
Omit os_expand_wildcards() change: Nvim's code is more complicated and
harder to refactor.
Co-authored-by: John Marriott <basilisk@internode.on.net>
Diffstat (limited to 'src/nvim/path.c')
-rw-r--r-- | src/nvim/path.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index 1ebc318809..08a63eacd0 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1875,11 +1875,12 @@ void path_fix_case(char *name) return; } + size_t taillen = strlen(tail); 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)) { + if (STRICMP(tail, entry) == 0 && taillen == strlen(entry)) { char newname[MAXPATHL + 1]; // Verify the inode is equal. @@ -2270,14 +2271,12 @@ int append_path(char *path, const char *to_append, size_t max_len) // Combine the path segments, separated by a slash. if (current_length > 0 && !vim_ispathsep_nocolon(path[current_length - 1])) { - current_length += 1; // Count the trailing slash. - // +1 for the NUL at the end. - if (current_length + 1 > max_len) { - return FAIL; + if (current_length + STRLEN_LITERAL(PATHSEPSTR) + 1 > max_len) { + return FAIL; // No space for trailing slash. } - - xstrlcat(path, PATHSEPSTR, max_len); + xstrlcpy(path + current_length, PATHSEPSTR, max_len - current_length); + current_length += STRLEN_LITERAL(PATHSEPSTR); } // +1 for the NUL at the end. @@ -2285,7 +2284,7 @@ int append_path(char *path, const char *to_append, size_t max_len) return FAIL; } - xstrlcat(path, to_append, max_len); + xstrlcpy(path + current_length, to_append, max_len - current_length); return OK; } |