aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/cmdexpand.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/cmdexpand.c')
-rw-r--r--src/nvim/cmdexpand.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c
index f172646edf..808df44941 100644
--- a/src/nvim/cmdexpand.c
+++ b/src/nvim/cmdexpand.c
@@ -1294,7 +1294,7 @@ char *addstar(char *fname, size_t len, int context)
}
} else {
retval = xmalloc(len + 4);
- xstrlcpy(retval, fname, len + 1);
+ xmemcpyz(retval, fname, len);
// Don't add a star to *, ~, ~user, $var or `cmd`.
// * would become **, which walks the whole tree.
@@ -2598,7 +2598,8 @@ static char *get_healthcheck_names(expand_T *xp FUNC_ATTR_UNUSED, int idx)
last_gen = get_cmdline_last_prompt_id();
}
- if (names.type == kObjectTypeArray && idx < (int)names.data.array.size) {
+ if (names.type == kObjectTypeArray && idx < (int)names.data.array.size
+ && names.data.array.items[idx].type == kObjectTypeString) {
return names.data.array.items[idx].data.string.data;
}
return NULL;
@@ -2938,7 +2939,7 @@ void ExpandGeneric(const char *const pat, expand_T *xp, regmatch_T *regmatch, ch
static void expand_shellcmd_onedir(char *buf, char *s, size_t l, char *pat, char ***matches,
int *numMatches, int flags, hashtab_T *ht, garray_T *gap)
{
- xstrlcpy(buf, s, l + 1);
+ xmemcpyz(buf, s, l);
add_pathsep(buf);
l = strlen(buf);
xstrlcpy(buf + l, pat, MAXPATHL - l);
@@ -2986,7 +2987,6 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int
char *path = NULL;
garray_T ga;
char *buf = xmalloc(MAXPATHL);
- char *e;
int flags = flagsarg;
bool did_curdir = false;
@@ -3022,7 +3022,7 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int
ga_init(&ga, (int)sizeof(char *), 10);
hashtab_T found_ht;
hash_init(&found_ht);
- for (char *s = path;; s = e) {
+ for (char *s = path, *e;; s = e) {
e = vim_strchr(s, ENV_SEPCHAR);
if (e == NULL) {
e = s + strlen(s);
@@ -3047,6 +3047,7 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int
if (l > MAXPATHL - 5) {
break;
}
+ assert(l <= strlen(s));
expand_shellcmd_onedir(buf, s, l, pat, matches, numMatches, flags, &found_ht, &ga);
if (*e != NUL) {
e++;
@@ -3241,6 +3242,7 @@ static int ExpandUserLua(expand_T *xp, int *num_file, char ***file)
/// Adds matches to `ga`.
/// If "dirs" is true only expand directory names.
void globpath(char *path, char *file, garray_T *ga, int expand_options, bool dirs)
+ FUNC_ATTR_NONNULL_ALL
{
expand_T xpc;
ExpandInit(&xpc);