mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 08:18:17 +00:00
Merge #708 'Remove NULL/non-NULL tests after vim_str(n)save'
- replace alloc with xmalloc
This commit is contained in:
476
src/nvim/eval.c
476
src/nvim/eval.c
@@ -1040,8 +1040,6 @@ var_redir_start (
|
||||
|
||||
/* Make a copy of the name, it is used in redir_lval until redir ends. */
|
||||
redir_varname = vim_strsave(name);
|
||||
if (redir_varname == NULL)
|
||||
return FAIL;
|
||||
|
||||
redir_lval = xcalloc(1, sizeof(lval_T));
|
||||
|
||||
@@ -1457,12 +1455,11 @@ int get_spellword(list_T *list, char_u **pp)
|
||||
*/
|
||||
typval_T *eval_expr(char_u *arg, char_u **nextcmd)
|
||||
{
|
||||
typval_T *tv;
|
||||
typval_T *tv = xmalloc(sizeof(typval_T));
|
||||
|
||||
tv = (typval_T *)alloc(sizeof(typval_T));
|
||||
if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) {
|
||||
if (eval0(arg, tv, nextcmd, TRUE) == FAIL) {
|
||||
free(tv);
|
||||
tv = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return tv;
|
||||
@@ -1485,7 +1482,6 @@ call_vim_function (
|
||||
typval_T *rettv
|
||||
)
|
||||
{
|
||||
typval_T *argvars;
|
||||
long n;
|
||||
int len;
|
||||
int i;
|
||||
@@ -1493,9 +1489,7 @@ call_vim_function (
|
||||
void *save_funccalp = NULL;
|
||||
int ret;
|
||||
|
||||
argvars = (typval_T *)alloc((unsigned)((argc + 1) * sizeof(typval_T)));
|
||||
if (argvars == NULL)
|
||||
return FAIL;
|
||||
typval_T *argvars = xmalloc((argc + 1) * sizeof(typval_T));
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
/* Pass a NULL or empty argument as an empty string */
|
||||
@@ -2541,8 +2535,6 @@ get_lval (
|
||||
lp->ll_newkey = vim_strnsave(key, len);
|
||||
if (len == -1)
|
||||
clear_tv(&var1);
|
||||
if (lp->ll_newkey == NULL)
|
||||
p = NULL;
|
||||
break;
|
||||
}
|
||||
/* existing variable, need to check if it can be changed */
|
||||
@@ -3429,20 +3421,19 @@ void del_menutrans_vars(void)
|
||||
static char_u *cat_prefix_varname(int prefix, char_u *name);
|
||||
|
||||
static char_u *varnamebuf = NULL;
|
||||
static int varnamebuflen = 0;
|
||||
static size_t varnamebuflen = 0;
|
||||
|
||||
/*
|
||||
* Function to concatenate a prefix and a variable name.
|
||||
*/
|
||||
static char_u *cat_prefix_varname(int prefix, char_u *name)
|
||||
{
|
||||
int len;
|
||||
size_t len = STRLEN(name) + 3;
|
||||
|
||||
len = (int)STRLEN(name) + 3;
|
||||
if (len > varnamebuflen) {
|
||||
free(varnamebuf);
|
||||
len += 10; /* some additional space */
|
||||
varnamebuf = alloc(len);
|
||||
varnamebuf = xmalloc(len);
|
||||
if (varnamebuf == NULL) {
|
||||
varnamebuflen = 0;
|
||||
return NULL;
|
||||
@@ -4924,9 +4915,7 @@ static int get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
|
||||
* Copy the string into allocated memory, handling backslashed
|
||||
* characters.
|
||||
*/
|
||||
name = alloc((unsigned)(p - *arg + extra));
|
||||
if (name == NULL)
|
||||
return FAIL;
|
||||
name = xmalloc(p - *arg + extra);
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = name;
|
||||
|
||||
@@ -5041,9 +5030,7 @@ static int get_lit_string_tv(char_u **arg, typval_T *rettv, int evaluate)
|
||||
/*
|
||||
* Copy the string into allocated memory, handling '' to ' reduction.
|
||||
*/
|
||||
str = alloc((unsigned)((p - *arg) - reduce));
|
||||
if (str == NULL)
|
||||
return FAIL;
|
||||
str = xmalloc((p - *arg) - reduce);
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = str;
|
||||
|
||||
@@ -5192,7 +5179,7 @@ list_free (
|
||||
*/
|
||||
listitem_T *listitem_alloc(void)
|
||||
{
|
||||
return (listitem_T *)alloc(sizeof(listitem_T));
|
||||
return xmalloc(sizeof(listitem_T));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -6157,17 +6144,12 @@ dict_free (
|
||||
* Allocate a Dictionary item.
|
||||
* The "key" is copied to the new item.
|
||||
* Note that the value of the item "di_tv" still needs to be initialized!
|
||||
* Returns NULL when out of memory.
|
||||
*/
|
||||
dictitem_T *dictitem_alloc(char_u *key)
|
||||
{
|
||||
dictitem_T *di;
|
||||
|
||||
di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) + STRLEN(key)));
|
||||
if (di != NULL) {
|
||||
STRCPY(di->di_key, key);
|
||||
di->di_flags = 0;
|
||||
}
|
||||
dictitem_T *di = xmalloc(sizeof(dictitem_T) + STRLEN(key));
|
||||
STRCPY(di->di_key, key);
|
||||
di->di_flags = 0;
|
||||
return di;
|
||||
}
|
||||
|
||||
@@ -6176,15 +6158,12 @@ dictitem_T *dictitem_alloc(char_u *key)
|
||||
*/
|
||||
static dictitem_T *dictitem_copy(dictitem_T *org)
|
||||
{
|
||||
dictitem_T *di;
|
||||
dictitem_T *di = xmalloc(sizeof(dictitem_T) + STRLEN(org->di_key));
|
||||
|
||||
STRCPY(di->di_key, org->di_key);
|
||||
di->di_flags = 0;
|
||||
copy_tv(&org->di_tv, &di->di_tv);
|
||||
|
||||
di = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
|
||||
+ STRLEN(org->di_key)));
|
||||
if (di != NULL) {
|
||||
STRCPY(di->di_key, org->di_key);
|
||||
di->di_flags = 0;
|
||||
copy_tv(&org->di_tv, &di->di_tv);
|
||||
}
|
||||
return di;
|
||||
}
|
||||
|
||||
@@ -6352,8 +6331,6 @@ dictitem_T *dict_find(dict_T *d, char_u *key, int len)
|
||||
akey = key;
|
||||
else if (len >= AKEYLEN) {
|
||||
tofree = akey = vim_strnsave(key, len);
|
||||
if (akey == NULL)
|
||||
return NULL;
|
||||
} else {
|
||||
/* Avoid a malloc/free by using buf[]. */
|
||||
vim_strncpy(buf, key, len);
|
||||
@@ -6673,34 +6650,33 @@ static char_u *tv2string(typval_T *tv, char_u **tofree, char_u *numbuf, int copy
|
||||
*/
|
||||
static char_u *string_quote(char_u *str, int function)
|
||||
{
|
||||
unsigned len;
|
||||
char_u *p, *r, *s;
|
||||
|
||||
len = (function ? 13 : 3);
|
||||
size_t len = (function ? 13 : 3);
|
||||
if (str != NULL) {
|
||||
len += (unsigned)STRLEN(str);
|
||||
len += STRLEN(str);
|
||||
for (p = str; *p != NUL; mb_ptr_adv(p))
|
||||
if (*p == '\'')
|
||||
++len;
|
||||
}
|
||||
s = r = alloc(len);
|
||||
if (r != NULL) {
|
||||
if (function) {
|
||||
STRCPY(r, "function('");
|
||||
r += 10;
|
||||
} else
|
||||
*r++ = '\'';
|
||||
if (str != NULL)
|
||||
for (p = str; *p != NUL; ) {
|
||||
if (*p == '\'')
|
||||
*r++ = '\'';
|
||||
MB_COPY_CHAR(p, r);
|
||||
}
|
||||
s = r = xmalloc(len);
|
||||
|
||||
if (function) {
|
||||
STRCPY(r, "function('");
|
||||
r += 10;
|
||||
} else
|
||||
*r++ = '\'';
|
||||
if (function)
|
||||
*r++ = ')';
|
||||
*r++ = NUL;
|
||||
}
|
||||
if (str != NULL)
|
||||
for (p = str; *p != NUL; ) {
|
||||
if (*p == '\'')
|
||||
*r++ = '\'';
|
||||
MB_COPY_CHAR(p, r);
|
||||
}
|
||||
*r++ = '\'';
|
||||
if (function)
|
||||
*r++ = ')';
|
||||
*r++ = NUL;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -7262,8 +7238,6 @@ call_func (
|
||||
/* Make a copy of the name, if it comes from a funcref variable it could
|
||||
* be changed or deleted in the called function. */
|
||||
name = vim_strnsave(funcname, len);
|
||||
if (name == NULL)
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* In a script change <SID>name() and s:name() to K_SNR 123_name().
|
||||
@@ -7288,13 +7262,9 @@ call_func (
|
||||
STRCPY(fname_buf + i, name + llen);
|
||||
fname = fname_buf;
|
||||
} else {
|
||||
fname = alloc((unsigned)(i + STRLEN(name + llen) + 1));
|
||||
if (fname == NULL)
|
||||
error = ERROR_OTHER;
|
||||
else {
|
||||
memmove(fname, fname_buf, (size_t)i);
|
||||
STRCPY(fname + i, name + llen);
|
||||
}
|
||||
fname = xmalloc(i + STRLEN(name + llen) + 1);
|
||||
memmove(fname, fname_buf, (size_t)i);
|
||||
STRCPY(fname + i, name + llen);
|
||||
}
|
||||
} else
|
||||
fname = name;
|
||||
@@ -9257,20 +9227,18 @@ static void f_foldtext(typval_T *argvars, typval_T *rettv)
|
||||
}
|
||||
}
|
||||
txt = _("+-%s%3ld lines: ");
|
||||
r = alloc((unsigned)(STRLEN(txt)
|
||||
+ STRLEN(vimvars[VV_FOLDDASHES].vv_str) /* for %s */
|
||||
+ 20 /* for %3ld */
|
||||
+ STRLEN(s))); /* concatenated */
|
||||
if (r != NULL) {
|
||||
sprintf((char *)r, txt, vimvars[VV_FOLDDASHES].vv_str,
|
||||
(long)((linenr_T)vimvars[VV_FOLDEND].vv_nr
|
||||
- (linenr_T)vimvars[VV_FOLDSTART].vv_nr + 1));
|
||||
len = (int)STRLEN(r);
|
||||
STRCAT(r, s);
|
||||
/* remove 'foldmarker' and 'commentstring' */
|
||||
foldtext_cleanup(r + len);
|
||||
rettv->vval.v_string = r;
|
||||
}
|
||||
r = xmalloc(STRLEN(txt)
|
||||
+ STRLEN(vimvars[VV_FOLDDASHES].vv_str) // for %s
|
||||
+ 20 // for %3ld
|
||||
+ STRLEN(s)); // concatenated
|
||||
sprintf((char *)r, txt, vimvars[VV_FOLDDASHES].vv_str,
|
||||
(long)((linenr_T)vimvars[VV_FOLDEND].vv_nr
|
||||
- (linenr_T)vimvars[VV_FOLDSTART].vv_nr + 1));
|
||||
len = (int)STRLEN(r);
|
||||
STRCAT(r, s);
|
||||
/* remove 'foldmarker' and 'commentstring' */
|
||||
foldtext_cleanup(r + len);
|
||||
rettv->vval.v_string = r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9331,12 +9299,9 @@ static void f_function(typval_T *argvars, typval_T *rettv)
|
||||
* would also work, but some plugins depend on the name being
|
||||
* printable text. */
|
||||
sprintf(sid_buf, "<SNR>%" PRId64 "_", (int64_t)current_SID);
|
||||
rettv->vval.v_string =
|
||||
alloc((int)(STRLEN(sid_buf) + STRLEN(s + off) + 1));
|
||||
if (rettv->vval.v_string != NULL) {
|
||||
STRCPY(rettv->vval.v_string, sid_buf);
|
||||
STRCAT(rettv->vval.v_string, s + off);
|
||||
}
|
||||
rettv->vval.v_string = xmalloc(STRLEN(sid_buf) + STRLEN(s + off) + 1);
|
||||
STRCPY(rettv->vval.v_string, sid_buf);
|
||||
STRCAT(rettv->vval.v_string, s + off);
|
||||
} else
|
||||
rettv->vval.v_string = vim_strsave(s);
|
||||
rettv->v_type = VAR_FUNC;
|
||||
@@ -9625,11 +9590,8 @@ static void f_getcmdpos(typval_T *argvars, typval_T *rettv)
|
||||
static void f_getcmdtype(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = alloc(2);
|
||||
if (rettv->vval.v_string != NULL) {
|
||||
rettv->vval.v_string[0] = get_cmdline_type();
|
||||
rettv->vval.v_string[1] = NUL;
|
||||
}
|
||||
rettv->vval.v_string = xmallocz(1);
|
||||
rettv->vval.v_string[0] = get_cmdline_type();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -9641,17 +9603,14 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv)
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = NULL;
|
||||
cwd = alloc(MAXPATHL);
|
||||
if (cwd != NULL) {
|
||||
if (os_dirname(cwd, MAXPATHL) != FAIL) {
|
||||
rettv->vval.v_string = vim_strsave(cwd);
|
||||
cwd = xmalloc(MAXPATHL);
|
||||
if (os_dirname(cwd, MAXPATHL) != FAIL) {
|
||||
rettv->vval.v_string = vim_strsave(cwd);
|
||||
#ifdef BACKSLASH_IN_FILENAME
|
||||
if (rettv->vval.v_string != NULL)
|
||||
slash_adjust(rettv->vval.v_string);
|
||||
slash_adjust(rettv->vval.v_string);
|
||||
#endif
|
||||
}
|
||||
free(cwd);
|
||||
}
|
||||
free(cwd);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -9675,11 +9634,9 @@ static void f_getfperm(typval_T *argvars, typval_T *rettv)
|
||||
int32_t file_perm = os_getperm(filename);
|
||||
if (file_perm >= 0) {
|
||||
perm = vim_strsave((char_u *)"---------");
|
||||
if (perm != NULL) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (file_perm & (1 << (8 - i)))
|
||||
perm[i] = flags[i % 3];
|
||||
}
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (file_perm & (1 << (8 - i)))
|
||||
perm[i] = flags[i % 3];
|
||||
}
|
||||
}
|
||||
rettv->v_type = VAR_STRING;
|
||||
@@ -11758,8 +11715,6 @@ static int mkdir_recurse(char_u *dir, int prot)
|
||||
|
||||
/* If the directory exists we're done. Otherwise: create it.*/
|
||||
updir = vim_strnsave(dir, (int)(p - dir));
|
||||
if (updir == NULL)
|
||||
return FAIL;
|
||||
if (os_isdir(updir))
|
||||
r = OK;
|
||||
else if (mkdir_recurse(updir, prot) == OK)
|
||||
@@ -11971,7 +11926,6 @@ static void f_printf(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
char_u buf[NUMBUFLEN];
|
||||
int len;
|
||||
char_u *s;
|
||||
int saved_did_emsg = did_emsg;
|
||||
char *fmt;
|
||||
|
||||
@@ -11980,11 +11934,9 @@ static void f_printf(typval_T *argvars, typval_T *rettv)
|
||||
fmt = (char *)get_tv_string_buf(&argvars[0], buf);
|
||||
len = vim_vsnprintf(NULL, 0, fmt, ap, argvars + 1);
|
||||
if (!did_emsg) {
|
||||
s = alloc(len + 1);
|
||||
if (s != NULL) {
|
||||
rettv->vval.v_string = s;
|
||||
(void)vim_vsnprintf((char *)s, len + 1, fmt, ap, argvars + 1);
|
||||
}
|
||||
char *s = xmalloc(len + 1);
|
||||
rettv->vval.v_string = (char_u *)s;
|
||||
(void)vim_vsnprintf(s, len + 1, fmt, ap, argvars + 1);
|
||||
}
|
||||
did_emsg |= saved_did_emsg;
|
||||
}
|
||||
@@ -12104,17 +12056,11 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)
|
||||
/* Change "prev" buffer to be the right size. This way
|
||||
* the bytes are only copied once, and very long lines are
|
||||
* allocated only once. */
|
||||
if ((s = xrealloc(prev, prevlen + len + 1)) != NULL) {
|
||||
memmove(s + prevlen, start, len);
|
||||
s[prevlen + len] = NUL;
|
||||
prev = NULL; /* the list will own the string */
|
||||
prevlen = prevsize = 0;
|
||||
}
|
||||
}
|
||||
if (s == NULL) {
|
||||
do_outofmem_msg((long_u) prevlen + len + 1);
|
||||
failed = TRUE;
|
||||
break;
|
||||
s = xrealloc(prev, prevlen + len + 1);
|
||||
memcpy(s + prevlen, start, len);
|
||||
s[prevlen + len] = NUL;
|
||||
prev = NULL; /* the list will own the string */
|
||||
prevlen = prevsize = 0;
|
||||
}
|
||||
|
||||
if ((li = listitem_alloc()) == NULL) {
|
||||
@@ -12174,8 +12120,6 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)
|
||||
if (start < p) {
|
||||
/* There's part of a line in buf, store it in "prev". */
|
||||
if (p - start + prevlen >= prevsize) {
|
||||
/* need bigger "prev" buffer */
|
||||
char_u *newprev;
|
||||
|
||||
/* A common use case is ordinary text files and "prev" gets a
|
||||
* fragment of a line, so the first allocation is made
|
||||
@@ -12188,14 +12132,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv)
|
||||
long growmin = (long)((p - start) * 2 + prevlen);
|
||||
prevsize = grow50pc > growmin ? grow50pc : growmin;
|
||||
}
|
||||
newprev = prev == NULL ? alloc(prevsize)
|
||||
: xrealloc(prev, prevsize);
|
||||
if (newprev == NULL) {
|
||||
do_outofmem_msg((long_u)prevsize);
|
||||
failed = TRUE;
|
||||
break;
|
||||
}
|
||||
prev = newprev;
|
||||
prev = xrealloc(prev, prevsize);
|
||||
}
|
||||
/* Add the line part to end of "prev". */
|
||||
memmove(prev + prevlen, start, p - start);
|
||||
@@ -12432,10 +12369,6 @@ static void f_repeat(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
char_u *p;
|
||||
int n;
|
||||
int slen;
|
||||
int len;
|
||||
char_u *r;
|
||||
int i;
|
||||
|
||||
n = get_tv_number(&argvars[1]);
|
||||
if (argvars[0].v_type == VAR_LIST) {
|
||||
@@ -12453,17 +12386,14 @@ static void f_repeat(typval_T *argvars, typval_T *rettv)
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = NULL;
|
||||
|
||||
slen = (int)STRLEN(p);
|
||||
len = slen * n;
|
||||
int slen = (int)STRLEN(p);
|
||||
int len = slen * n;
|
||||
if (len <= 0)
|
||||
return;
|
||||
|
||||
r = alloc(len + 1);
|
||||
if (r != NULL) {
|
||||
for (i = 0; i < n; i++)
|
||||
memmove(r + i * slen, p, (size_t)slen);
|
||||
r[len] = NUL;
|
||||
}
|
||||
char_u *r = xmallocz(len);
|
||||
for (int i = 0; i < n; i++)
|
||||
memmove(r + i * slen, p, (size_t)slen);
|
||||
|
||||
rettv->vval.v_string = r;
|
||||
}
|
||||
@@ -12521,9 +12451,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
|
||||
q[-1] = NUL;
|
||||
}
|
||||
|
||||
buf = alloc(MAXPATHL + 1);
|
||||
if (buf == NULL)
|
||||
goto fail;
|
||||
buf = xmallocz(MAXPATHL);
|
||||
|
||||
for (;; ) {
|
||||
for (;; ) {
|
||||
@@ -12569,13 +12497,11 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
|
||||
}
|
||||
if (q > p && !path_is_absolute_path(buf)) {
|
||||
/* symlink is relative to directory of argument */
|
||||
cpy = alloc((unsigned)(STRLEN(p) + STRLEN(buf) + 1));
|
||||
if (cpy != NULL) {
|
||||
STRCPY(cpy, p);
|
||||
STRCPY(path_tail(cpy), buf);
|
||||
free(p);
|
||||
p = cpy;
|
||||
}
|
||||
cpy = xmalloc(STRLEN(p) + STRLEN(buf) + 1);
|
||||
STRCPY(cpy, p);
|
||||
STRCPY(path_tail(cpy), buf);
|
||||
free(p);
|
||||
p = cpy;
|
||||
} else {
|
||||
free(p);
|
||||
p = vim_strsave(buf);
|
||||
@@ -12589,11 +12515,10 @@ static void f_resolve(typval_T *argvars, typval_T *rettv)
|
||||
q = path_next_component(remain + 1);
|
||||
len = q - remain - (*q != NUL);
|
||||
cpy = vim_strnsave(p, STRLEN(p) + len);
|
||||
if (cpy != NULL) {
|
||||
STRNCAT(cpy, remain, len);
|
||||
free(p);
|
||||
p = cpy;
|
||||
}
|
||||
STRNCAT(cpy, remain, len);
|
||||
free(p);
|
||||
p = cpy;
|
||||
|
||||
/* Shorten "remain". */
|
||||
if (*q != NUL)
|
||||
STRMOVE(remain, q - 1);
|
||||
@@ -13083,10 +13008,8 @@ do_searchpair (
|
||||
|
||||
/* Make two search patterns: start/end (pat2, for in nested pairs) and
|
||||
* start/middle/end (pat3, for the top pair). */
|
||||
pat2 = alloc((unsigned)(STRLEN(spat) + STRLEN(epat) + 15));
|
||||
pat3 = alloc((unsigned)(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23));
|
||||
if (pat2 == NULL || pat3 == NULL)
|
||||
goto theend;
|
||||
pat2 = xmalloc(STRLEN(spat) + STRLEN(epat) + 15);
|
||||
pat3 = xmalloc(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 23);
|
||||
sprintf((char *)pat2, "\\(%s\\m\\)\\|\\(%s\\m\\)", spat, epat);
|
||||
if (*mpat == NUL)
|
||||
STRCPY(pat3, pat2);
|
||||
@@ -13177,7 +13100,6 @@ do_searchpair (
|
||||
if ((flags & SP_NOMOVE) || retval == 0)
|
||||
curwin->w_cursor = save_cursor;
|
||||
|
||||
theend:
|
||||
free(pat2);
|
||||
free(pat3);
|
||||
if (p_cpo == empty_option)
|
||||
@@ -13261,13 +13183,11 @@ static void f_setbufvar(typval_T *argvars, typval_T *rettv)
|
||||
if (!error && strval != NULL)
|
||||
set_option_value(varname, numval, strval, OPT_LOCAL);
|
||||
} else {
|
||||
bufvarname = alloc((unsigned)STRLEN(varname) + 3);
|
||||
if (bufvarname != NULL) {
|
||||
STRCPY(bufvarname, "b:");
|
||||
STRCPY(bufvarname + 2, varname);
|
||||
set_var(bufvarname, varp, TRUE);
|
||||
free(bufvarname);
|
||||
}
|
||||
bufvarname = xmalloc(STRLEN(varname) + 3);
|
||||
STRCPY(bufvarname, "b:");
|
||||
STRCPY(bufvarname + 2, varname);
|
||||
set_var(bufvarname, varp, TRUE);
|
||||
free(bufvarname);
|
||||
}
|
||||
|
||||
/* reset notion of buffer */
|
||||
@@ -13573,13 +13493,11 @@ static void f_settabvar(typval_T *argvars, typval_T *rettv)
|
||||
save_curtab = curtab;
|
||||
goto_tabpage_tp(tp, FALSE, FALSE);
|
||||
|
||||
tabvarname = alloc((unsigned)STRLEN(varname) + 3);
|
||||
if (tabvarname != NULL) {
|
||||
STRCPY(tabvarname, "t:");
|
||||
STRCPY(tabvarname + 2, varname);
|
||||
set_var(tabvarname, varp, TRUE);
|
||||
free(tabvarname);
|
||||
}
|
||||
tabvarname = xmalloc(STRLEN(varname) + 3);
|
||||
STRCPY(tabvarname, "t:");
|
||||
STRCPY(tabvarname + 2, varname);
|
||||
set_var(tabvarname, varp, TRUE);
|
||||
free(tabvarname);
|
||||
|
||||
/* Restore current tabpage */
|
||||
if (valid_tabpage(save_curtab))
|
||||
@@ -13643,13 +13561,11 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off)
|
||||
if (!error && strval != NULL)
|
||||
set_option_value(varname, numval, strval, OPT_LOCAL);
|
||||
} else {
|
||||
winvarname = alloc((unsigned)STRLEN(varname) + 3);
|
||||
if (winvarname != NULL) {
|
||||
STRCPY(winvarname, "w:");
|
||||
STRCPY(winvarname + 2, varname);
|
||||
set_var(winvarname, varp, TRUE);
|
||||
free(winvarname);
|
||||
}
|
||||
winvarname = xmalloc(STRLEN(varname) + 3);
|
||||
STRCPY(winvarname, "w:");
|
||||
STRCPY(winvarname + 2, varname);
|
||||
set_var(winvarname, varp, TRUE);
|
||||
free(winvarname);
|
||||
}
|
||||
|
||||
restore_win(save_curwin, save_curtab, TRUE);
|
||||
@@ -14831,7 +14747,7 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv)
|
||||
tagname_T tn;
|
||||
|
||||
rettv_list_alloc(rettv);
|
||||
fname = alloc(MAXPATHL);
|
||||
fname = xmalloc(MAXPATHL);
|
||||
|
||||
int first = TRUE;
|
||||
while (get_tagfname(&tn, first, fname) == OK) {
|
||||
@@ -14924,33 +14840,30 @@ static void f_tanh(typval_T *argvars, typval_T *rettv)
|
||||
*/
|
||||
static void f_tolower(typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
char_u *p;
|
||||
|
||||
p = vim_strsave(get_tv_string(&argvars[0]));
|
||||
char_u *p = vim_strsave(get_tv_string(&argvars[0]));
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = p;
|
||||
|
||||
if (p != NULL)
|
||||
while (*p != NUL) {
|
||||
int l;
|
||||
while (*p != NUL) {
|
||||
int l;
|
||||
|
||||
if (enc_utf8) {
|
||||
int c, lc;
|
||||
if (enc_utf8) {
|
||||
int c, lc;
|
||||
|
||||
c = utf_ptr2char(p);
|
||||
lc = utf_tolower(c);
|
||||
l = utf_ptr2len(p);
|
||||
/* TODO: reallocate string when byte count changes. */
|
||||
if (utf_char2len(lc) == l)
|
||||
utf_char2bytes(lc, p);
|
||||
p += l;
|
||||
} else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
|
||||
p += l; /* skip multi-byte character */
|
||||
else {
|
||||
*p = TOLOWER_LOC(*p); /* note that tolower() can be a macro */
|
||||
++p;
|
||||
}
|
||||
c = utf_ptr2char(p);
|
||||
lc = utf_tolower(c);
|
||||
l = utf_ptr2len(p);
|
||||
/* TODO: reallocate string when byte count changes. */
|
||||
if (utf_char2len(lc) == l)
|
||||
utf_char2bytes(lc, p);
|
||||
p += l;
|
||||
} else if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
|
||||
p += l; /* skip multi-byte character */
|
||||
else {
|
||||
*p = TOLOWER_LOC(*p); /* note that tolower() can be a macro */
|
||||
++p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -15773,13 +15686,11 @@ static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u *
|
||||
|
||||
temp_result = eval_to_string(expr_start + 1, &nextcmd, FALSE);
|
||||
if (temp_result != NULL && nextcmd == NULL) {
|
||||
retval = alloc((unsigned)(STRLEN(temp_result) + (expr_start - in_start)
|
||||
+ (in_end - expr_end) + 1));
|
||||
if (retval != NULL) {
|
||||
STRCPY(retval, in_start);
|
||||
STRCAT(retval, temp_result);
|
||||
STRCAT(retval, expr_end + 1);
|
||||
}
|
||||
retval = xmalloc(STRLEN(temp_result) + (expr_start - in_start)
|
||||
+ (in_end - expr_end) + 1);
|
||||
STRCPY(retval, in_start);
|
||||
STRCAT(retval, temp_result);
|
||||
STRCAT(retval, expr_end + 1);
|
||||
}
|
||||
free(temp_result);
|
||||
|
||||
@@ -15970,7 +15881,6 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
|
||||
{
|
||||
char_u *oldval;
|
||||
char_u *newval;
|
||||
unsigned len;
|
||||
|
||||
oldval = vimvars[VV_CMDARG].vv_str;
|
||||
if (eap == NULL) {
|
||||
@@ -15979,26 +15889,23 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t len = 0;
|
||||
if (eap->force_bin == FORCE_BIN)
|
||||
len = 6;
|
||||
else if (eap->force_bin == FORCE_NOBIN)
|
||||
len = 8;
|
||||
else
|
||||
len = 0;
|
||||
|
||||
if (eap->read_edit)
|
||||
len += 7;
|
||||
|
||||
if (eap->force_ff != 0)
|
||||
len += (unsigned)STRLEN(eap->cmd + eap->force_ff) + 6;
|
||||
len += STRLEN(eap->cmd + eap->force_ff) + 6;
|
||||
if (eap->force_enc != 0)
|
||||
len += (unsigned)STRLEN(eap->cmd + eap->force_enc) + 7;
|
||||
len += STRLEN(eap->cmd + eap->force_enc) + 7;
|
||||
if (eap->bad_char != 0)
|
||||
len += 7 + 4; /* " ++bad=" + "keep" or "drop" */
|
||||
|
||||
newval = alloc(len + 1);
|
||||
if (newval == NULL)
|
||||
return NULL;
|
||||
newval = xmalloc(len + 1);
|
||||
|
||||
if (eap->force_bin == FORCE_BIN)
|
||||
sprintf((char *)newval, " ++bin");
|
||||
@@ -16753,10 +16660,7 @@ set_var (
|
||||
if (!valid_varname(varname))
|
||||
return;
|
||||
|
||||
v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
|
||||
+ STRLEN(varname)));
|
||||
if (v == NULL)
|
||||
return;
|
||||
v = xmalloc(sizeof(dictitem_T) + STRLEN(varname));
|
||||
STRCPY(v->di_key, varname);
|
||||
if (hash_add(ht, DI2HIKEY(v)) == FAIL) {
|
||||
free(v);
|
||||
@@ -17412,8 +17316,6 @@ void ex_function(exarg_T *eap)
|
||||
c = *p;
|
||||
*p = NUL;
|
||||
arg = vim_strsave(arg);
|
||||
if (arg == NULL)
|
||||
goto erret;
|
||||
|
||||
/* Check for duplicate argument name. */
|
||||
for (i = 0; i < newargs.ga_len; ++i)
|
||||
@@ -17605,11 +17507,9 @@ void ex_function(exarg_T *eap)
|
||||
* allocates 250 bytes per line, this saves 80% on average. The cost
|
||||
* is an extra alloc/free. */
|
||||
p = vim_strsave(theline);
|
||||
if (p != NULL) {
|
||||
if (line_arg == NULL)
|
||||
free(theline);
|
||||
theline = p;
|
||||
}
|
||||
if (line_arg == NULL)
|
||||
free(theline);
|
||||
theline = p;
|
||||
|
||||
((char_u **)(newlines.ga_data))[newlines.ga_len++] = theline;
|
||||
|
||||
@@ -17678,8 +17578,6 @@ void ex_function(exarg_T *eap)
|
||||
free(name);
|
||||
sprintf(numbuf, "%d", ++func_nr);
|
||||
name = vim_strsave((char_u *)numbuf);
|
||||
if (name == NULL)
|
||||
goto erret;
|
||||
}
|
||||
|
||||
if (fp == NULL) {
|
||||
@@ -17709,9 +17607,7 @@ void ex_function(exarg_T *eap)
|
||||
}
|
||||
}
|
||||
|
||||
fp = (ufunc_T *)alloc((unsigned)(sizeof(ufunc_T) + STRLEN(name)));
|
||||
if (fp == NULL)
|
||||
goto erret;
|
||||
fp = xmalloc(sizeof(ufunc_T) + STRLEN(name));
|
||||
|
||||
if (fudi.fd_dict != NULL) {
|
||||
if (fudi.fd_di == NULL) {
|
||||
@@ -17939,18 +17835,16 @@ trans_function_name (
|
||||
}
|
||||
}
|
||||
|
||||
name = alloc((unsigned)(len + lead + 1));
|
||||
if (name != NULL) {
|
||||
if (lead > 0) {
|
||||
name[0] = K_SPECIAL;
|
||||
name[1] = KS_EXTRA;
|
||||
name[2] = (int)KE_SNR;
|
||||
if (lead > 3) /* If it's "<SID>" */
|
||||
STRCPY(name + 3, sid_buf);
|
||||
}
|
||||
memmove(name + lead, lv.ll_name, (size_t)len);
|
||||
name[lead + len] = NUL;
|
||||
name = xmalloc(len + lead + 1);
|
||||
if (lead > 0){
|
||||
name[0] = K_SPECIAL;
|
||||
name[1] = KS_EXTRA;
|
||||
name[2] = (int)KE_SNR;
|
||||
if (lead > 3) /* If it's "<SID>" */
|
||||
STRCPY(name + 3, sid_buf);
|
||||
}
|
||||
memmove(name + lead, lv.ll_name, (size_t)len);
|
||||
name[lead + len] = NUL;
|
||||
*pp = end;
|
||||
|
||||
theend:
|
||||
@@ -18160,7 +18054,7 @@ void func_dump_profile(FILE *fd)
|
||||
if (todo == 0)
|
||||
return; /* nothing to dump */
|
||||
|
||||
sorttab = (ufunc_T **)alloc((unsigned)(sizeof(ufunc_T) * todo));
|
||||
sorttab = xmalloc(sizeof(ufunc_T) * todo);
|
||||
|
||||
for (hi = func_hashtab.ht_array; todo > 0; ++hi) {
|
||||
if (!HASHITEM_EMPTY(hi)) {
|
||||
@@ -18338,9 +18232,7 @@ static char_u *autoload_name(char_u *name)
|
||||
char_u *scriptname;
|
||||
|
||||
/* Get the script file name: replace '#' with '/', append ".vim". */
|
||||
scriptname = alloc((unsigned)(STRLEN(name) + 14));
|
||||
if (scriptname == NULL)
|
||||
return FALSE;
|
||||
scriptname = xmalloc(STRLEN(name) + 14);
|
||||
STRCPY(scriptname, "autoload/");
|
||||
STRCAT(scriptname, name);
|
||||
*vim_strrchr(scriptname, AUTOLOAD_CHAR) = NUL;
|
||||
@@ -18555,7 +18447,7 @@ call_user_func (
|
||||
|
||||
line_breakcheck(); /* check for CTRL-C hit */
|
||||
|
||||
fc = (funccall_T *)alloc(sizeof(funccall_T));
|
||||
fc = xmalloc(sizeof(funccall_T));
|
||||
fc->caller = current_funccal;
|
||||
current_funccal = fc;
|
||||
fc->func = fp;
|
||||
@@ -18636,10 +18528,7 @@ call_user_func (
|
||||
v = &fc->fixvar[fixvar_idx++].var;
|
||||
v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
|
||||
} else {
|
||||
v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
|
||||
+ STRLEN(name)));
|
||||
if (v == NULL)
|
||||
break;
|
||||
v = xmalloc(sizeof(dictitem_T) + STRLEN(name));
|
||||
v->di_flags = DI_FLAGS_RO;
|
||||
}
|
||||
STRCPY(v->di_key, name);
|
||||
@@ -18662,10 +18551,9 @@ call_user_func (
|
||||
save_sourcing_name = sourcing_name;
|
||||
save_sourcing_lnum = sourcing_lnum;
|
||||
sourcing_lnum = 1;
|
||||
sourcing_name = alloc((unsigned)((save_sourcing_name == NULL ? 0
|
||||
: STRLEN(save_sourcing_name)) +
|
||||
STRLEN(fp->uf_name) + 13));
|
||||
if (sourcing_name != NULL) {
|
||||
sourcing_name = xmalloc((save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name))
|
||||
+ STRLEN(fp->uf_name) + 13);
|
||||
{
|
||||
if (save_sourcing_name != NULL
|
||||
&& STRNCMP(save_sourcing_name, "function ", 9) == 0)
|
||||
sprintf((char *)sourcing_name, "%s..", save_sourcing_name);
|
||||
@@ -19522,11 +19410,9 @@ repeat:
|
||||
/* Only replace it when it starts with '~' */
|
||||
if (*dirname == '~') {
|
||||
s = vim_strsave(dirname);
|
||||
if (s != NULL) {
|
||||
*fnamep = s;
|
||||
free(*bufp);
|
||||
*bufp = s;
|
||||
}
|
||||
*fnamep = s;
|
||||
free(*bufp);
|
||||
*bufp = s;
|
||||
}
|
||||
}
|
||||
free(pbuf);
|
||||
@@ -19547,11 +19433,8 @@ repeat:
|
||||
*fnamelen = (int)(tail - *fnamep);
|
||||
if (*fnamelen == 0) {
|
||||
/* Result is empty. Turn it into "." to make ":cd %:h" work. */
|
||||
p = vim_strsave((char_u *)".");
|
||||
if (p == NULL)
|
||||
return -1;
|
||||
free(*bufp);
|
||||
*bufp = *fnamep = tail = p;
|
||||
*bufp = *fnamep = tail = vim_strsave((char_u *)".");
|
||||
*fnamelen = 1;
|
||||
} else {
|
||||
while (tail > s && !after_pathsep(s, tail))
|
||||
@@ -19625,29 +19508,23 @@ repeat:
|
||||
p = vim_strchr(s, sep);
|
||||
if (p != NULL) {
|
||||
pat = vim_strnsave(s, (int)(p - s));
|
||||
if (pat != NULL) {
|
||||
s = p + 1;
|
||||
/* find end of substitution */
|
||||
p = vim_strchr(s, sep);
|
||||
if (p != NULL) {
|
||||
sub = vim_strnsave(s, (int)(p - s));
|
||||
str = vim_strnsave(*fnamep, *fnamelen);
|
||||
if (sub != NULL && str != NULL) {
|
||||
*usedlen = (int)(p + 1 - src);
|
||||
s = do_string_sub(str, pat, sub, flags);
|
||||
if (s != NULL) {
|
||||
*fnamep = s;
|
||||
*fnamelen = (int)STRLEN(s);
|
||||
free(*bufp);
|
||||
*bufp = s;
|
||||
didit = TRUE;
|
||||
}
|
||||
}
|
||||
free(sub);
|
||||
free(str);
|
||||
}
|
||||
free(pat);
|
||||
s = p + 1;
|
||||
/* find end of substitution */
|
||||
p = vim_strchr(s, sep);
|
||||
if (p != NULL) {
|
||||
sub = vim_strnsave(s, (int)(p - s));
|
||||
str = vim_strnsave(*fnamep, *fnamelen);
|
||||
*usedlen = (int)(p + 1 - src);
|
||||
s = do_string_sub(str, pat, sub, flags);
|
||||
*fnamep = s;
|
||||
*fnamelen = (int)STRLEN(s);
|
||||
free(*bufp);
|
||||
*bufp = s;
|
||||
didit = TRUE;
|
||||
free(sub);
|
||||
free(str);
|
||||
}
|
||||
free(pat);
|
||||
}
|
||||
/* after using ":s", repeat all the modifiers */
|
||||
if (didit)
|
||||
@@ -19679,7 +19556,6 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
|
||||
int do_all;
|
||||
char_u *tail;
|
||||
garray_T ga;
|
||||
char_u *ret;
|
||||
char_u *save_cpo;
|
||||
char_u *zero_width = NULL;
|
||||
|
||||
@@ -19738,7 +19614,7 @@ char_u *do_string_sub(char_u *str, char_u *pat, char_u *sub, char_u *flags)
|
||||
vim_regfree(regmatch.regprog);
|
||||
}
|
||||
|
||||
ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data);
|
||||
char_u *ret = vim_strsave(ga.ga_data == NULL ? str : (char_u *)ga.ga_data);
|
||||
ga_clear(&ga);
|
||||
if (p_cpo == empty_option)
|
||||
p_cpo = save_cpo;
|
||||
|
Reference in New Issue
Block a user