aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ops.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-11-10 08:39:21 +0800
committerGitHub <noreply@github.com>2023-11-10 08:39:21 +0800
commitcd63a9addd6e1114c3524fa041ece560550cfe7b (patch)
tree846797f471b5de4c230838620ceaeda860de9e17 /src/nvim/ops.c
parentae8ca79920a8d0e928ac1502a10d1d063a06cae5 (diff)
downloadrneovim-cd63a9addd6e1114c3524fa041ece560550cfe7b.tar.gz
rneovim-cd63a9addd6e1114c3524fa041ece560550cfe7b.tar.bz2
rneovim-cd63a9addd6e1114c3524fa041ece560550cfe7b.zip
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.
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r--src/nvim/ops.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 9dbeed8658..b56d5e11ea 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -1366,7 +1366,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg)
cnt = find_ident_under_cursor(argp, (regname == Ctrl_W
? (FIND_IDENT|FIND_STRING)
: FIND_STRING));
- *argp = cnt ? xstrnsave(*argp, cnt) : NULL;
+ *argp = cnt ? xmemdupz(*argp, cnt) : NULL;
*allocated = true;
return true;
@@ -2404,7 +2404,7 @@ void op_insert(oparg_T *oap, int count1)
}
int ins_len = (int)strlen(firstline) - pre_textlen - offset;
if (pre_textlen >= 0 && ins_len > 0) {
- char *ins_text = xstrnsave(firstline, (size_t)ins_len);
+ char *ins_text = xmemdupz(firstline, (size_t)ins_len);
// block handled here
if (u_save(oap->start.lnum, (linenr_T)(oap->end.lnum + 1)) == OK) {
block_insert(oap, ins_text, (oap->op_type == OP_INSERT), &bd);
@@ -3118,7 +3118,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
if (dir == FORWARD && *p != NUL) {
MB_PTR_ADV(p);
}
- ptr = xstrnsave(oldp, (size_t)(p - oldp));
+ ptr = xmemdupz(oldp, (size_t)(p - oldp));
ml_replace(curwin->w_cursor.lnum, ptr, false);
nr_lines++;
dir = FORWARD;