aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/os/fs.c6
-rw-r--r--src/nvim/os/shell.c10
-rw-r--r--src/nvim/path.c15
3 files changed, 16 insertions, 15 deletions
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index d0da37b8e7..451994241d 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -370,8 +370,8 @@ static bool is_executable_in_path(const char *name, char **abspath)
char *path = xstrdup(path_env);
#endif
- size_t buf_len = strlen(name) + strlen(path) + 2;
- char *buf = xmalloc(buf_len);
+ const size_t bufsize = strlen(name) + strlen(path) + 2;
+ char *buf = xmalloc(bufsize);
// Walk through all entries in $PATH to check if "name" exists there and
// is an executable file.
@@ -382,7 +382,7 @@ static bool is_executable_in_path(const char *name, char **abspath)
// Combine the $PATH segment with `name`.
xmemcpyz(buf, p, (size_t)(e - p));
- (void)append_path(buf, name, buf_len);
+ (void)append_path(buf, name, bufsize);
#ifdef MSWIN
if (is_executable_ext(buf, abspath)) {
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index 5347c8db9a..d60d0b3e55 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -1208,10 +1208,11 @@ static void read_input(StringBuilder *buf)
size_t len = 0;
linenr_T lnum = curbuf->b_op_start.lnum;
char *lp = ml_get(lnum);
+ size_t lplen = (size_t)ml_get_len(lnum);
while (true) {
- size_t l = strlen(lp + written);
- if (l == 0) {
+ lplen -= written;
+ if (lplen == 0) {
len = 0;
} else if (lp[written] == NL) {
// NL -> NUL translation
@@ -1219,11 +1220,11 @@ static void read_input(StringBuilder *buf)
kv_push(*buf, NUL);
} else {
char *s = vim_strchr(lp + written, NL);
- len = s == NULL ? l : (size_t)(s - (lp + written));
+ len = s == NULL ? lplen : (size_t)(s - (lp + written));
kv_concat_len(*buf, lp + written, len);
}
- if (len == l) {
+ if (len == lplen) {
// Finished a line, add a NL, unless this line should not have one.
if (lnum != curbuf->b_op_end.lnum
|| (!curbuf->b_p_bin && curbuf->b_p_fixeol)
@@ -1236,6 +1237,7 @@ static void read_input(StringBuilder *buf)
break;
}
lp = ml_get(lnum);
+ lplen = (size_t)ml_get_len(lnum);
written = 0;
} else if (len > 0) {
written += len;
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;
}