Remove simpler cases of OOM error handling (after *alloc calls)

By simpler cases I mean cases where the OOM error is not expected to be handled
by the caller of the function that calls `alloc`, `lalloc`, `xrealloc`,
`xmalloc`, `alloc_clear`, and `lalloc_clear`.

These are the functions that:

 - Do not return an allocated buffer
 - Have OOM as the only error condition

I took note of the functions that expect the caller to handle the OOM error and
will go through them to check all the callers that may be handling OOM error in
future commits.

I'm ignoring eval.c and ex_.c in this series of commits. eval.c will soon be
obsolete and I will deal with ex_.c in later PRs.
This commit is contained in:
Felipe Oliveira Carvalho
2014-04-01 01:41:39 -03:00
committed by Thiago de Arruda
parent 6bbffee0a5
commit 13848aadbf
39 changed files with 944 additions and 1499 deletions

View File

@@ -1369,10 +1369,6 @@ buflist_new (
}
if (buf != curbuf || curbuf == NULL) {
buf = (buf_T *)alloc_clear((unsigned)sizeof(buf_T));
if (buf == NULL) {
vim_free(ffname);
return NULL;
}
/* init b: variables */
buf->b_vars = dict_alloc();
if (buf->b_vars == NULL) {
@@ -1391,8 +1387,7 @@ buflist_new (
clear_wininfo(buf);
buf->b_wininfo = (wininfo_T *)alloc_clear((unsigned)sizeof(wininfo_T));
if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL))
|| buf->b_wininfo == NULL) {
if (ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) {
vim_free(buf->b_ffname);
buf->b_ffname = NULL;
vim_free(buf->b_sfname);
@@ -1837,8 +1832,6 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
/* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */
if (*pat == '^') {
patc = alloc((unsigned)STRLEN(pat) + 11);
if (patc == NULL)
return FAIL;
STRCPY(patc, "\\(^\\|[\\/]\\)");
STRCPY(patc + 11, pat + 1);
} else
@@ -2001,8 +1994,6 @@ static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col,
if (wip == NULL) {
/* allocate a new entry */
wip = (wininfo_T *)alloc_clear((unsigned)sizeof(wininfo_T));
if (wip == NULL)
return;
wip->wi_win = win;
if (lnum == 0) /* set lnum even when it's 0 */
lnum = 1;
@@ -2523,8 +2514,6 @@ fileinfo (
size_t len;
buffer = alloc(IOSIZE);
if (buffer == NULL)
return;
if (fullname > 1) { /* 2 CTRL-G: include buffer number */
vim_snprintf((char *)buffer, IOSIZE, "buf %d: ", curbuf->b_fnum);
@@ -3700,8 +3689,6 @@ do_arg_all (
opened_len = ARGCOUNT;
opened = alloc_clear((unsigned)opened_len);
if (opened == NULL)
return;
/* Autocommands may do anything to the argument list. Make sure it's not
* freed while we are working here by "locking" it. We still have to
@@ -4292,8 +4279,6 @@ void write_viminfo_bufferlist(FILE *fp)
/* Allocate room for the file name, lnum and col. */
#define LINE_BUF_LEN (MAXPATHL + 40)
line = alloc(LINE_BUF_LEN);
if (line == NULL)
return;
FOR_ALL_TAB_WINDOWS(tp, win)
set_last_cursor(win);
@@ -4380,26 +4365,24 @@ static void insert_sign(
signlist_T *newsign;
newsign = (signlist_T *)lalloc((long_u)sizeof(signlist_T), FALSE);
if (newsign != NULL) {
newsign->id = id;
newsign->lnum = lnum;
newsign->typenr = typenr;
newsign->next = next;
newsign->id = id;
newsign->lnum = lnum;
newsign->typenr = typenr;
newsign->next = next;
if (prev == NULL) {
/* When adding first sign need to redraw the windows to create the
* column for signs. */
if (buf->b_signlist == NULL) {
redraw_buf_later(buf, NOT_VALID);
changed_cline_bef_curs();
}
if (prev == NULL) {
/* When adding first sign need to redraw the windows to create the
* column for signs. */
if (buf->b_signlist == NULL) {
redraw_buf_later(buf, NOT_VALID);
changed_cline_bef_curs();
}
/* first sign in signlist */
buf->b_signlist = newsign;
}
else {
prev->next = newsign;
}
/* first sign in signlist */
buf->b_signlist = newsign;
}
else {
prev->next = newsign;
}
}