aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/nvim/api/command.c2
-rw-r--r--src/nvim/api/private/helpers.h2
-rw-r--r--src/nvim/autocmd.c4
-rw-r--r--src/nvim/cmdexpand.c6
-rw-r--r--src/nvim/context.c2
-rw-r--r--src/nvim/digraph.c4
-rw-r--r--src/nvim/eval.c18
-rw-r--r--src/nvim/eval/funcs.c6
-rw-r--r--src/nvim/eval/userfunc.c12
-rw-r--r--src/nvim/eval/vars.c2
-rw-r--r--src/nvim/ex_cmds.c2
-rw-r--r--src/nvim/ex_docmd.c4
-rw-r--r--src/nvim/file_search.c2
-rw-r--r--src/nvim/fileio.c2
-rw-r--r--src/nvim/indent.c4
-rw-r--r--src/nvim/mapping.c2
-rw-r--r--src/nvim/match.c2
-rw-r--r--src/nvim/menu.c4
-rw-r--r--src/nvim/normal.c2
-rw-r--r--src/nvim/ops.c6
-rw-r--r--src/nvim/option.c4
-rw-r--r--src/nvim/optionstr.c2
-rw-r--r--src/nvim/os/env.c9
-rw-r--r--src/nvim/os/stdpaths.c2
-rw-r--r--src/nvim/path.c2
-rw-r--r--src/nvim/search.c2
-rw-r--r--src/nvim/sign.c12
-rw-r--r--src/nvim/spell.c2
-rw-r--r--src/nvim/spellsuggest.c2
-rw-r--r--src/nvim/strings.c2
-rw-r--r--src/nvim/tag.c2
-rw-r--r--src/nvim/window.c2
32 files changed, 64 insertions, 67 deletions
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c
index f4c6f646eb..9d51f2a4dc 100644
--- a/src/nvim/api/command.c
+++ b/src/nvim/api/command.c
@@ -419,7 +419,7 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error
VALIDATE_EXP(!string_iswhite(elem.data.string), "command arg", "non-whitespace", NULL, {
goto end;
});
- data_str = xstrndup(elem.data.string.data, elem.data.string.size);
+ data_str = string_to_cstr(elem.data.string);
break;
default:
VALIDATE_EXP(false, "command arg", "valid type", api_typename(elem.type), {
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h
index 9cf4620acd..8911e145e7 100644
--- a/src/nvim/api/private/helpers.h
+++ b/src/nvim/api/private/helpers.h
@@ -75,8 +75,6 @@
#define PUT_C(dict, k, v) \
kv_push_c(dict, ((KeyValuePair) { .key = cstr_as_string(k), .value = v }))
-#define PUT_BOOL(dict, name, condition) PUT(dict, name, BOOLEAN_OBJ(condition));
-
#define ADD(array, item) \
kv_push(array, item)
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index bdb3983ab3..1a83dd30c0 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -1031,7 +1031,7 @@ int autocmd_register(int64_t id, event_T event, const char *pat, int patlen, int
}
ap->refcount = 0;
- ap->pat = xstrnsave(pat, (size_t)patlen);
+ ap->pat = xmemdupz(pat, (size_t)patlen);
ap->patlen = patlen;
// need to initialize last_mode for the first ModeChanged autocmd
@@ -2514,7 +2514,7 @@ static int arg_augroup_get(char **argp)
return AUGROUP_ALL;
}
- char *group_name = xstrnsave(arg, (size_t)(p - arg));
+ char *group_name = xmemdupz(arg, (size_t)(p - arg));
int group = augroup_find(group_name);
if (group == AUGROUP_ERROR) {
group = AUGROUP_ALL; // no match, use all groups
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c
index 496c047a4a..6b83664339 100644
--- a/src/nvim/cmdexpand.c
+++ b/src/nvim/cmdexpand.c
@@ -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,
}));
}
diff --git a/src/nvim/context.c b/src/nvim/context.c
index fe5a49faa2..9b1eee56c5 100644
--- a/src/nvim/context.c
+++ b/src/nvim/context.c
@@ -330,7 +330,7 @@ static inline msgpack_sbuffer array_to_sbuf(Array array)
typval_T list_tv;
Error err = ERROR_INIT;
- object_to_vim(ARRAY_OBJ(array), &list_tv, &err);
+ (void)object_to_vim(ARRAY_OBJ(array), &list_tv, &err);
if (!encode_vim_list_to_buf(list_tv.vval.v_list, &sbuf.size, &sbuf.data)) {
emsg(_("E474: Failed to convert list to msgpack string buffer"));
diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c
index 5f0dfb381d..de76d55977 100644
--- a/src/nvim/digraph.c
+++ b/src/nvim/digraph.c
@@ -2110,10 +2110,10 @@ void ex_loadkeymap(exarg_T *eap)
if ((*p != '"') && (*p != NUL)) {
kmap_T *kp = GA_APPEND_VIA_PTR(kmap_T, &curbuf->b_kmap_ga);
s = skiptowhite(p);
- kp->from = xstrnsave(p, (size_t)(s - p));
+ kp->from = xmemdupz(p, (size_t)(s - p));
p = skipwhite(s);
s = skiptowhite(p);
- kp->to = xstrnsave(p, (size_t)(s - p));
+ kp->to = xmemdupz(p, (size_t)(s - p));
if ((strlen(kp->from) + strlen(kp->to) >= KMAP_LLEN)
|| (*kp->from == NUL)
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index a3ea5169fd..390cdbb377 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -1633,7 +1633,7 @@ char *get_lval(char *const name, typval_T *const rettv, lval_T *const lp, const
if (len == -1) {
lp->ll_newkey = xstrdup(key);
} else {
- lp->ll_newkey = xstrnsave(key, (size_t)len);
+ lp->ll_newkey = xmemdupz(key, (size_t)len);
}
tv_clear(&var1);
break;
@@ -1966,7 +1966,7 @@ bool next_for_item(void *fi_void, char *arg)
typval_T tv;
tv.v_type = VAR_STRING;
tv.v_lock = VAR_FIXED;
- tv.vval.v_string = xstrnsave(fi->fi_string + fi->fi_byte_idx, (size_t)len);
+ tv.vval.v_string = xmemdupz(fi->fi_string + fi->fi_byte_idx, (size_t)len);
fi->fi_byte_idx += len;
const int result
= ex_let_vars(arg, &tv, true, fi->fi_semicolon, fi->fi_varcount, false, NULL) == OK;
@@ -4893,7 +4893,7 @@ static int get_literal_key(char **arg, typval_T *tv)
}
for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; p++) {}
tv->v_type = VAR_STRING;
- tv->vval.v_string = xstrnsave(*arg, (size_t)(p - *arg));
+ tv->vval.v_string = xmemdupz(*arg, (size_t)(p - *arg));
*arg = skipwhite(p);
return OK;
@@ -5242,7 +5242,7 @@ static void filter_map_string(const char *str, filtermap_T filtermap, typval_T *
typval_T tv = {
.v_type = VAR_STRING,
.v_lock = VAR_UNLOCKED,
- .vval.v_string = xstrnsave(p, (size_t)len),
+ .vval.v_string = xmemdupz(p, (size_t)len),
};
vimvars[VV_KEY].vv_nr = idx;
@@ -7483,7 +7483,7 @@ char *char_from_string(const char *str, varnumber_T index)
if (nbyte >= slen) {
return NULL;
}
- return xstrnsave(str + nbyte, (size_t)utf_ptr2len(str + nbyte));
+ return xmemdupz(str + nbyte, (size_t)utf_ptr2len(str + nbyte));
}
/// Get the byte index for character index "idx" in string "str" with length
@@ -7544,7 +7544,7 @@ char *string_slice(const char *str, varnumber_T first, varnumber_T last, bool ex
if (start_byte >= (ssize_t)slen || end_byte <= start_byte) {
return NULL;
}
- return xstrnsave(str + start_byte, (size_t)(end_byte - start_byte));
+ return xmemdupz(str + start_byte, (size_t)(end_byte - start_byte));
}
/// Handle:
@@ -8586,13 +8586,13 @@ repeat:
// find end of pattern
p = vim_strchr(s, sep);
if (p != NULL) {
- char *const pat = xstrnsave(s, (size_t)(p - s));
+ char *const pat = xmemdupz(s, (size_t)(p - s));
s = p + 1;
// find end of substitution
p = vim_strchr(s, sep);
if (p != NULL) {
- char *const sub = xstrnsave(s, (size_t)(p - s));
- char *const str = xstrnsave(*fnamep, *fnamelen);
+ char *const sub = xmemdupz(s, (size_t)(p - s));
+ char *const str = xmemdupz(*fnamep, *fnamelen);
*usedlen = (size_t)(p + 1 - src);
s = do_string_sub(str, pat, sub, NULL, flags);
*fnamep = s;
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 550d296093..36d368a913 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -5669,7 +5669,7 @@ static void read_file_or_blob(typval_T *argvars, typval_T *rettv, bool always_bl
}
if (prevlen == 0) {
assert(len < INT_MAX);
- s = xstrnsave(start, len);
+ s = xmemdupz(start, len);
} else {
// Change "prev" buffer to be the right size. This way
// the bytes are only copied once, and very long lines are
@@ -6305,7 +6305,7 @@ static void reduce_string(typval_T *argvars, typval_T *expr, typval_T *rettv)
*rettv = (typval_T){
.v_type = VAR_STRING,
.v_lock = VAR_UNLOCKED,
- .vval.v_string = xstrnsave(p, (size_t)len),
+ .vval.v_string = xmemdupz(p, (size_t)len),
};
p += len;
} else if (tv_check_for_string_arg(argvars, 2) == FAIL) {
@@ -6321,7 +6321,7 @@ static void reduce_string(typval_T *argvars, typval_T *expr, typval_T *rettv)
argv[1] = (typval_T){
.v_type = VAR_STRING,
.v_lock = VAR_UNLOCKED,
- .vval.v_string = xstrnsave(p, (size_t)len),
+ .vval.v_string = xmemdupz(p, (size_t)len),
};
const int r = eval_expr_typval(expr, true, argv, 2, rettv);
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 6e7b1e4d67..4b50710649 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -1625,7 +1625,7 @@ int call_func(const char *funcname, int len, typval_T *rettv, int argcount_in, t
if (fp == NULL) {
// Make a copy of the name, if it comes from a funcref variable it could
// be changed or deleted in the called function.
- name = xstrnsave(funcname, (size_t)len);
+ name = xmemdupz(funcname, (size_t)len);
fname = fname_trans_sid(name, fname_buf, &tofree, &error);
}
@@ -2089,7 +2089,7 @@ char *save_function_name(char **name, bool skip, int flags, funcdict_T *fudi)
if (strncmp(p, "<lambda>", 8) == 0) {
p += 8;
(void)getdigits(&p, false, 0);
- saved = xstrndup(*name, (size_t)(p - *name));
+ saved = xmemdupz(*name, (size_t)(p - *name));
if (fudi != NULL) {
CLEAR_POINTER(fudi);
}
@@ -2573,12 +2573,12 @@ void ex_function(exarg_T *eap)
if (strncmp(p, "trim", 4) == 0) {
// Ignore leading white space.
p = skipwhite(p + 4);
- heredoc_trimmed = xstrnsave(theline, (size_t)(skipwhite(theline) - theline));
+ heredoc_trimmed = xmemdupz(theline, (size_t)(skipwhite(theline) - theline));
}
if (*p == NUL) {
skip_until = xstrdup(".");
} else {
- skip_until = xstrnsave(p, (size_t)(skiptowhite(p) - p));
+ skip_until = xmemdupz(p, (size_t)(skiptowhite(p) - p));
}
do_concat = false;
is_heredoc = true;
@@ -2598,7 +2598,7 @@ void ex_function(exarg_T *eap)
if (strncmp(p, "trim", 4) == 0) {
// Ignore leading white space.
p = skipwhite(p + 4);
- heredoc_trimmed = xstrnsave(theline, (size_t)(skipwhite(theline) - theline));
+ heredoc_trimmed = xmemdupz(theline, (size_t)(skipwhite(theline) - theline));
continue;
}
if (strncmp(p, "eval", 4) == 0) {
@@ -2608,7 +2608,7 @@ void ex_function(exarg_T *eap)
}
break;
}
- skip_until = xstrnsave(p, (size_t)(skiptowhite(p) - p));
+ skip_until = xmemdupz(p, (size_t)(skiptowhite(p) - p));
do_concat = false;
is_heredoc = true;
}
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c
index 33256b78e1..ed79d8a681 100644
--- a/src/nvim/eval/vars.c
+++ b/src/nvim/eval/vars.c
@@ -274,7 +274,7 @@ list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
p++;
text_indent_len++;
}
- text_indent = xstrnsave(theline, (size_t)text_indent_len);
+ text_indent = xmemdupz(theline, (size_t)text_indent_len);
}
// with "trim": skip the indent matching the first line
if (text_indent != NULL) {
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 2857465db0..bb3284a6b8 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -2816,7 +2816,7 @@ void ex_append(exarg_T *eap)
if (p == NULL) {
p = eap->nextcmd + strlen(eap->nextcmd);
}
- theline = xstrnsave(eap->nextcmd, (size_t)(p - eap->nextcmd));
+ theline = xmemdupz(eap->nextcmd, (size_t)(p - eap->nextcmd));
if (*p != NUL) {
p++;
}
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index c83b00f77f..ad09ee6bb1 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -2033,7 +2033,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
while (ASCII_ISALNUM(*p)) {
p++;
}
- p = xstrnsave(ea.cmd, (size_t)(p - ea.cmd));
+ p = xmemdupz(ea.cmd, (size_t)(p - ea.cmd));
int ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, true, NULL);
xfree(p);
// If the autocommands did something and didn't cause an error, try
@@ -7121,7 +7121,7 @@ char *eval_vars(char *src, const char *srcstart, size_t *usedlen, linenr_T *lnum
}
result = NULL;
} else {
- result = xstrnsave(result, resultlen);
+ result = xmemdupz(result, resultlen);
}
xfree(resultbuf);
return result;
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index 796769d7ff..5bdaaa880e 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -293,7 +293,7 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i
xstrlcpy(ff_expand_buffer, rel_fname, len + 1);
search_ctx->ffsc_start_dir = FullName_save(ff_expand_buffer, false);
} else {
- search_ctx->ffsc_start_dir = xstrnsave(rel_fname, len);
+ search_ctx->ffsc_start_dir = xmemdupz(rel_fname, len);
}
if (*++path != NUL) {
path++;
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 804c9cec11..424bd33b6c 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -1993,7 +1993,7 @@ static char *next_fenc(char **pp, bool *alloced)
r = enc_canonize(*pp);
*pp += strlen(*pp);
} else {
- r = xstrnsave(*pp, (size_t)(p - *pp));
+ r = xmemdupz(*pp, (size_t)(p - *pp));
*pp = p + 1;
p = enc_canonize(r);
xfree(r);
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 65eabd72c3..ff21b11abb 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -960,7 +960,7 @@ void ex_retab(exarg_T *eap)
return;
}
while (ascii_isdigit(*(eap->arg)) || *(eap->arg) == ',') {
- (eap->arg)++;
+ eap->arg++;
}
// This ensures that either new_vts_array and new_ts_str are freshly
@@ -970,7 +970,7 @@ void ex_retab(exarg_T *eap)
new_vts_array = curbuf->b_p_vts_array;
new_ts_str = NULL;
} else {
- new_ts_str = xstrnsave(new_ts_str, (size_t)(eap->arg - new_ts_str));
+ new_ts_str = xmemdupz(new_ts_str, (size_t)(eap->arg - new_ts_str));
}
for (lnum = eap->line1; !got_int && lnum <= eap->line2; lnum++) {
char *ptr = ml_get(lnum);
diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c
index 2ee1e2e02d..b54b07fc20 100644
--- a/src/nvim/mapping.c
+++ b/src/nvim/mapping.c
@@ -1654,7 +1654,7 @@ char *eval_map_expr(mapblock_T *mp, int c)
Array args = ARRAY_DICT_INIT;
Object ret = nlua_call_ref(mp->m_luaref, NULL, args, true, &err);
if (ret.type == kObjectTypeString) {
- p = xstrndup(ret.data.string.data, ret.data.string.size);
+ p = string_to_cstr(ret.data.string);
}
api_free_object(ret);
if (err.type != kErrorTypeNone) {
diff --git a/src/nvim/match.c b/src/nvim/match.c
index e087d4f45d..d153ea042d 100644
--- a/src/nvim/match.c
+++ b/src/nvim/match.c
@@ -1216,7 +1216,7 @@ void ex_match(exarg_T *eap)
} else {
p = skiptowhite(eap->arg);
if (!eap->skip) {
- g = xstrnsave(eap->arg, (size_t)(p - eap->arg));
+ g = xmemdupz(eap->arg, (size_t)(p - eap->arg));
}
p = skipwhite(p);
if (*p == NUL) {
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index 5eb8b41015..5fa731141e 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -1313,7 +1313,7 @@ static char *menu_text(const char *str, int *mnemonic, char **actext)
*actext = xstrdup(p + 1);
}
assert(p >= str);
- text = xstrnsave(str, (size_t)(p - str));
+ text = xmemdupz(str, (size_t)(p - str));
} else {
text = xstrdup(str);
}
@@ -1736,7 +1736,7 @@ void ex_menutranslate(exarg_T *eap)
from = xstrdup(from);
from_noamp = menu_text(from, NULL, NULL);
assert(arg >= to);
- to = xstrnsave(to, (size_t)(arg - to));
+ to = xmemdupz(to, (size_t)(arg - to));
menu_translate_tab_and_shift(from);
menu_translate_tab_and_shift(to);
menu_unescape_name(from);
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 54e1e49d97..418097a82a 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -4232,7 +4232,7 @@ static void nv_brackets(cmdarg_T *cap)
clearop(cap->oap);
} else {
// Make a copy, if the line was changed it will be freed.
- ptr = xstrnsave(ptr, len);
+ ptr = xmemdupz(ptr, len);
find_pattern_in_path(ptr, 0, len, true,
cap->count0 == 0 ? !isupper(cap->nchar) : false,
(((cap->nchar & 0xf) == ('d' & 0xf))
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;
diff --git a/src/nvim/option.c b/src/nvim/option.c
index b44dda67d6..7005b63cac 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -630,7 +630,7 @@ void set_init_3(void)
size_t len = 0;
char *p = (char *)invocation_path_tail(p_sh, &len);
- p = xstrnsave(p, len);
+ p = xmemdupz(p, len);
{
//
@@ -5749,7 +5749,7 @@ int ExpandSettingSubtract(expand_T *xp, regmatch_T *regmatch, int *numMatches, c
// If more than one flags, split the flags up and expose each
// character as individual choice.
for (char *flag = option_val; *flag != NUL; flag++) {
- (*matches)[count++] = xstrnsave(flag, 1);
+ (*matches)[count++] = xmemdupz(flag, 1);
}
}
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c
index b868c90108..7aea47cfff 100644
--- a/src/nvim/optionstr.c
+++ b/src/nvim/optionstr.c
@@ -635,7 +635,7 @@ static int expand_set_opt_listflag(optexpand_T *args, char *flags, int *numMatch
// existing flag. Just skip it to avoid duplicate.
continue;
}
- (*matches)[count++] = xstrnsave(flag, 1);
+ (*matches)[count++] = xmemdupz(flag, 1);
}
}
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 7de7168d62..dbea6f01df 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -292,12 +292,11 @@ char *os_getenvname_at_index(size_t index)
// Some Windows env vars start with =, so skip over that to find the
// separator between name/value
- const char * const end = strchr(utf8_str + (utf8_str[0] == '=' ? 1 : 0),
- '=');
+ const char *const end = strchr(utf8_str + (utf8_str[0] == '=' ? 1 : 0), '=');
assert(end != NULL);
ptrdiff_t len = end - utf8_str;
assert(len > 0);
- name = xstrndup(utf8_str, (size_t)len);
+ name = xmemdupz(utf8_str, (size_t)len);
xfree(utf8_str);
break;
}
@@ -328,7 +327,7 @@ char *os_getenvname_at_index(size_t index)
assert(end != NULL);
ptrdiff_t len = end - str;
assert(len > 0);
- return xstrndup(str, (size_t)len);
+ return xmemdupz(str, (size_t)len);
#endif
}
@@ -960,7 +959,7 @@ char *vim_getenv(const char *name)
// check that the result is a directory name
assert(vim_path_end >= vim_path);
- vim_path = xstrndup(vim_path, (size_t)(vim_path_end - vim_path));
+ vim_path = xmemdupz(vim_path, (size_t)(vim_path_end - vim_path));
if (!os_isdir(vim_path)) {
xfree(vim_path);
diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c
index fa474b67dd..8ea30ff21e 100644
--- a/src/nvim/os/stdpaths.c
+++ b/src/nvim/os/stdpaths.c
@@ -127,7 +127,7 @@ char *stdpaths_get_xdg_var(const XDGVarType idx)
ret = "/tmp/";
}
size_t len = strlen(ret);
- ret = xstrndup(ret, len >= 2 ? len - 1 : 0); // Trim trailing slash.
+ ret = xmemdupz(ret, len >= 2 ? len - 1 : 0); // Trim trailing slash.
}
return ret;
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 15a8762da1..8cc824337c 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1374,7 +1374,7 @@ static int expand_backtick(garray_T *gap, char *pat, int flags)
int cnt = 0;
// Create the command: lop off the backticks.
- char *cmd = xstrnsave(pat + 1, strlen(pat) - 2);
+ char *cmd = xmemdupz(pat + 1, strlen(pat) - 2);
if (*cmd == '=') { // `={expr}`: Expand expression
buffer = eval_to_string(cmd + 1, true);
diff --git a/src/nvim/search.c b/src/nvim/search.c
index e253abaa41..cee526d416 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -1629,7 +1629,7 @@ static bool find_rawstring_end(char *linep, pos_T *startpos, pos_T *endpos)
for (p = linep + startpos->col + 1; *p && *p != '('; p++) {}
size_t delim_len = (size_t)((p - linep) - startpos->col - 1);
- char *delim_copy = xstrnsave(linep + startpos->col + 1, delim_len);
+ char *delim_copy = xmemdupz(linep + startpos->col + 1, delim_len);
bool found = false;
for (lnum = startpos->lnum; lnum <= endpos->lnum; lnum++) {
char *line = ml_get(lnum);
diff --git a/src/nvim/sign.c b/src/nvim/sign.c
index 97164f2234..6a6adbd866 100644
--- a/src/nvim/sign.c
+++ b/src/nvim/sign.c
@@ -1209,27 +1209,27 @@ static void sign_define_cmd(char *sign_name, char *cmdline)
if (strncmp(arg, "icon=", 5) == 0) {
arg += 5;
XFREE_CLEAR(icon);
- icon = xstrnsave(arg, (size_t)(p - arg));
+ icon = xmemdupz(arg, (size_t)(p - arg));
} else if (strncmp(arg, "text=", 5) == 0) {
arg += 5;
XFREE_CLEAR(text);
- text = xstrnsave(arg, (size_t)(p - arg));
+ text = xmemdupz(arg, (size_t)(p - arg));
} else if (strncmp(arg, "linehl=", 7) == 0) {
arg += 7;
XFREE_CLEAR(linehl);
- linehl = xstrnsave(arg, (size_t)(p - arg));
+ linehl = xmemdupz(arg, (size_t)(p - arg));
} else if (strncmp(arg, "texthl=", 7) == 0) {
arg += 7;
XFREE_CLEAR(texthl);
- texthl = xstrnsave(arg, (size_t)(p - arg));
+ texthl = xmemdupz(arg, (size_t)(p - arg));
} else if (strncmp(arg, "culhl=", 6) == 0) {
arg += 6;
XFREE_CLEAR(culhl);
- culhl = xstrnsave(arg, (size_t)(p - arg));
+ culhl = xmemdupz(arg, (size_t)(p - arg));
} else if (strncmp(arg, "numhl=", 6) == 0) {
arg += 6;
XFREE_CLEAR(numhl);
- numhl = xstrnsave(arg, (size_t)(p - arg));
+ numhl = xmemdupz(arg, (size_t)(p - arg));
} else {
semsg(_(e_invarg2), arg);
failed = true;
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index 4b1f8afb15..864a55b12b 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -2257,7 +2257,7 @@ static void use_midword(slang_T *lp, win_T *wp)
wp->w_s->b_spell_ismw[c] = true;
} else if (wp->w_s->b_spell_ismw_mb == NULL) {
// First multi-byte char in "b_spell_ismw_mb".
- wp->w_s->b_spell_ismw_mb = xstrnsave(p, (size_t)l);
+ wp->w_s->b_spell_ismw_mb = xmemdupz(p, (size_t)l);
} else {
// Append multi-byte chars to "b_spell_ismw_mb".
const int n = (int)strlen(wp->w_s->b_spell_ismw_mb);
diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c
index 938e8cec8f..15ec652859 100644
--- a/src/nvim/spellsuggest.c
+++ b/src/nvim/spellsuggest.c
@@ -3146,7 +3146,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i
if (i < 0) {
// Add a suggestion.
stp = GA_APPEND_VIA_PTR(suggest_T, gap);
- stp->st_word = xstrnsave(goodword, (size_t)goodlen);
+ stp->st_word = xmemdupz(goodword, (size_t)goodlen);
stp->st_wordlen = goodlen;
stp->st_score = score;
stp->st_altscore = altscore;
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index af82f5e578..26da38f284 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -2646,7 +2646,7 @@ void f_strcharpart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
rettv->v_type = VAR_STRING;
- rettv->vval.v_string = xstrndup(p + nbyte, (size_t)len);
+ rettv->vval.v_string = xmemdupz(p + nbyte, (size_t)len);
}
/// "strpart()" function
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index 1d4c85de49..7a175926d2 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -707,7 +707,7 @@ void do_tag(char *tag, int type, int count, int forceit, int verbose)
&& tagp2.user_data) {
XFREE_CLEAR(tagstack[tagstackidx].user_data);
tagstack[tagstackidx].user_data =
- xstrnsave(tagp2.user_data, (size_t)(tagp2.user_data_end - tagp2.user_data));
+ xmemdupz(tagp2.user_data, (size_t)(tagp2.user_data_end - tagp2.user_data));
}
tagstackidx++;
diff --git a/src/nvim/window.c b/src/nvim/window.c
index eee500f695..d1b8d7c7b5 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -586,7 +586,7 @@ wingotofile:
}
// Make a copy, if the line was changed it will be freed.
- ptr = xstrnsave(ptr, len);
+ ptr = xmemdupz(ptr, len);
find_pattern_in_path(ptr, 0, len, true, Prenum == 0,
type, Prenum1, ACTION_SPLIT, 1, MAXLNUM);