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.
This commit is contained in:
zeertzjq
2023-11-10 08:39:21 +08:00
committed by GitHub
parent ae8ca79920
commit cd63a9addd
32 changed files with 64 additions and 67 deletions

View File

@@ -804,7 +804,7 @@ static char *find_longest_match(expand_T *xp, int options)
}
}
return xstrndup(xp->xp_files[0], len);
return xmemdupz(xp->xp_files[0], len);
}
/// Do wildcard expansion on the string "str".
@@ -3156,11 +3156,11 @@ static int ExpandUserDefined(const char *const pat, expand_T *xp, regmatch_T *re
if (match) {
if (!fuzzy) {
GA_APPEND(char *, &ga, xstrnsave(s, (size_t)(e - s)));
GA_APPEND(char *, &ga, xmemdupz(s, (size_t)(e - s)));
} else {
GA_APPEND(fuzmatch_str_T, &ga, ((fuzmatch_str_T){
.idx = ga.ga_len,
.str = xstrnsave(s, (size_t)(e - s)),
.str = xmemdupz(s, (size_t)(e - s)),
.score = score,
}));
}