mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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:
parent
ae8ca79920
commit
cd63a9addd
@ -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), {
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
}));
|
||||
}
|
||||
|
@ -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"));
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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++;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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++;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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++;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user