mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
refactor: use xstpcpy() instead of strcat() (#25572)
This commit is contained in:
parent
9ff6f73f83
commit
468a3a1407
@ -899,7 +899,6 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode)
|
||||
|
||||
// Concatenate all matching names. Unless interrupted, this can be slow
|
||||
// and the result probably won't be used.
|
||||
// TODO(philix): use xstpcpy instead of strcat in a loop (ExpandOne)
|
||||
if (mode == WILD_ALL && xp->xp_numfiles > 0 && !got_int) {
|
||||
size_t len = 0;
|
||||
for (int i = 0; i < xp->xp_numfiles; i++) {
|
||||
@ -914,18 +913,19 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode)
|
||||
}
|
||||
ss = xmalloc(len);
|
||||
*ss = NUL;
|
||||
char *ssp = ss;
|
||||
for (int i = 0; i < xp->xp_numfiles; i++) {
|
||||
if (i > 0) {
|
||||
if (xp->xp_prefix == XP_PREFIX_NO) {
|
||||
STRCAT(ss, "no");
|
||||
ssp = xstpcpy(ssp, "no");
|
||||
} else if (xp->xp_prefix == XP_PREFIX_INV) {
|
||||
STRCAT(ss, "inv");
|
||||
ssp = xstpcpy(ssp, "inv");
|
||||
}
|
||||
}
|
||||
STRCAT(ss, xp->xp_files[i]);
|
||||
ssp = xstpcpy(ssp, xp->xp_files[i]);
|
||||
|
||||
if (i != xp->xp_numfiles - 1) {
|
||||
STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
|
||||
ssp = xstpcpy(ssp, (options & WILD_USE_NL) ? "\n" : " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -983,10 +983,12 @@ static int stuff_yank(int regname, char *p)
|
||||
yankreg_T *reg = get_yank_register(regname, YREG_YANK);
|
||||
if (is_append_register(regname) && reg->y_array != NULL) {
|
||||
char **pp = &(reg->y_array[reg->y_size - 1]);
|
||||
char *lp = xmalloc(strlen(*pp) + strlen(p) + 1);
|
||||
STRCPY(lp, *pp);
|
||||
// TODO(philix): use xstpcpy() in stuff_yank()
|
||||
STRCAT(lp, p);
|
||||
const size_t ppl = strlen(*pp);
|
||||
const size_t pl = strlen(p);
|
||||
char *lp = xmalloc(ppl + pl + 1);
|
||||
memcpy(lp, *pp, ppl);
|
||||
memcpy(lp + ppl, p, pl);
|
||||
*(lp + ppl + pl) = NUL;
|
||||
xfree(p);
|
||||
xfree(*pp);
|
||||
*pp = lp;
|
||||
|
Loading…
Reference in New Issue
Block a user