mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Remove OOM checks: suggested changes in review
- Replace a vim_strsave/free pair with xrealloc - Use xmallocz() in some places - Use xrealloc() and forget about the NULL pointer case - Remove invalid comment - Remove unnecessary checks - Replace a complicated xmalloc/STRCPY/free code chunk code with xrealloc() - Replace a vim_strsave/free code chunk with xrealloc()
This commit is contained in:
parent
7a830d945f
commit
e303a11ebf
@ -9592,9 +9592,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 = xmalloc(2);
|
||||
rettv->vval.v_string = xmallocz(1);
|
||||
rettv->vval.v_string[0] = get_cmdline_type();
|
||||
rettv->vval.v_string[1] = NUL;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -12124,8 +12123,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
|
||||
@ -12138,8 +12135,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) ? xmalloc(prevsize) : xrealloc(prev, prevsize);
|
||||
prev = newprev;
|
||||
prev = xrealloc(prev, prevsize);
|
||||
}
|
||||
/* Add the line part to end of "prev". */
|
||||
memmove(prev + prevlen, start, p - start);
|
||||
@ -12398,10 +12394,9 @@ static void f_repeat(typval_T *argvars, typval_T *rettv)
|
||||
if (len <= 0)
|
||||
return;
|
||||
|
||||
char_u *r = xmalloc(len + 1);
|
||||
char_u *r = xmallocz(len);
|
||||
for (int i = 0; i < n; i++)
|
||||
memmove(r + i * slen, p, (size_t)slen);
|
||||
r[len] = NUL;
|
||||
|
||||
rettv->vval.v_string = r;
|
||||
}
|
||||
@ -15708,7 +15703,7 @@ 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 = xmalloc(STRLEN(temp_result) + (expr_start - in_start)
|
||||
+ (in_end - expr_end) + 1);
|
||||
+ (in_end - expr_end) + 1);
|
||||
STRCPY(retval, in_start);
|
||||
STRCAT(retval, temp_result);
|
||||
STRCAT(retval, expr_end + 1);
|
||||
|
@ -1986,7 +1986,7 @@ static void alloc_cmdbuff(int len)
|
||||
else
|
||||
len += 20;
|
||||
|
||||
ccline.cmdbuff = xmalloc(len); /* caller should check for out-of-memory */
|
||||
ccline.cmdbuff = xmalloc(len);
|
||||
ccline.cmdbufflen = len;
|
||||
}
|
||||
|
||||
@ -2179,10 +2179,7 @@ void put_on_cmdline(char_u *str, int len, int redraw)
|
||||
if (len < 0)
|
||||
len = (int)STRLEN(str);
|
||||
|
||||
/* Check if ccline.cmdbuff needs to be longer */
|
||||
if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen) {
|
||||
realloc_cmdbuff(ccline.cmdlen + len + 1);
|
||||
}
|
||||
realloc_cmdbuff(ccline.cmdlen + len + 1);
|
||||
|
||||
if (!ccline.overstrike) {
|
||||
memmove(ccline.cmdbuff + ccline.cmdpos + len,
|
||||
|
@ -719,13 +719,10 @@ restofline:
|
||||
if (qfprev == NULL)
|
||||
goto error2;
|
||||
if (*errmsg && !multiignore) {
|
||||
len = (int)STRLEN(qfprev->qf_text);
|
||||
ptr = xmalloc(len + STRLEN(errmsg) + 2);
|
||||
STRCPY(ptr, qfprev->qf_text);
|
||||
free(qfprev->qf_text);
|
||||
qfprev->qf_text = ptr;
|
||||
*(ptr += len) = '\n';
|
||||
STRCPY(++ptr, errmsg);
|
||||
size_t len = STRLEN(qfprev->qf_text);
|
||||
qfprev->qf_text = xrealloc(qfprev->qf_text, len + STRLEN(errmsg) + 2);
|
||||
qfprev->qf_text[len] = '\n';
|
||||
STRCPY(qfprev->qf_text + len + 1, errmsg);
|
||||
}
|
||||
if (qfprev->qf_nr == -1)
|
||||
qfprev->qf_nr = enr;
|
||||
|
@ -4691,10 +4691,7 @@ win_redr_status_matches (
|
||||
if (matches == NULL) /* interrupted completion? */
|
||||
return;
|
||||
|
||||
if (has_mbyte)
|
||||
buf = xmalloc(Columns * MB_MAXBYTES + 1);
|
||||
else
|
||||
buf = xmalloc(Columns + 1);
|
||||
buf = xmalloc(has_mbyte ? Columns * MB_MAXBYTES + 1 : Columns + 1);
|
||||
|
||||
if (match == -1) { /* don't show match but original text */
|
||||
match = 0;
|
||||
|
@ -4304,14 +4304,9 @@ replace_termcodes (
|
||||
}
|
||||
result[dlen] = NUL;
|
||||
|
||||
/*
|
||||
* Copy the new string to allocated memory.
|
||||
* If this fails, just return from.
|
||||
*/
|
||||
*bufp = vim_strsave(result);
|
||||
from = *bufp;
|
||||
free(result);
|
||||
return from;
|
||||
*bufp = xrealloc(result, dlen + 1);
|
||||
|
||||
return *bufp;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user