aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-05-12 16:19:50 -0300
committerFelipe Oliveira Carvalho <felipekde@gmail.com>2014-05-19 14:50:26 -0300
commite303a11ebfc352860cce73184ece692ab4d0f01c (patch)
tree67a3e4b7a8d6633149f9d22f3f51cd96498aacd4 /src
parent7a830d945fb44a850b7cef65971f37a570a36e9e (diff)
downloadrneovim-e303a11ebfc352860cce73184ece692ab4d0f01c.tar.gz
rneovim-e303a11ebfc352860cce73184ece692ab4d0f01c.tar.bz2
rneovim-e303a11ebfc352860cce73184ece692ab4d0f01c.zip
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()
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c13
-rw-r--r--src/nvim/ex_getln.c7
-rw-r--r--src/nvim/quickfix.c11
-rw-r--r--src/nvim/screen.c5
-rw-r--r--src/nvim/term.c11
5 files changed, 14 insertions, 33 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 2f8e65df86..e738081b8d 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -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);
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index b507116ac3..278886cf5e 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -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,
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index a026cb46f5..269a33edcc 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -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;
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 53b2baf1bb..af3f5c999f 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -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;
diff --git a/src/nvim/term.c b/src/nvim/term.c
index 733bef8b5f..073ed30052 100644
--- a/src/nvim/term.c
+++ b/src/nvim/term.c
@@ -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;
}
/*