mirror of
https://github.com/neovim/neovim.git
synced 2025-10-03 08:28:34 +00:00
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:

committed by
Thiago de Arruda

parent
6bbffee0a5
commit
13848aadbf
37
src/regexp.c
37
src/regexp.c
@@ -1222,8 +1222,6 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
|
||||
|
||||
/* Allocate space. */
|
||||
r = (bt_regprog_T *)lalloc(sizeof(bt_regprog_T) + regsize, TRUE);
|
||||
if (r == NULL)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Second pass: emit code.
|
||||
@@ -3592,8 +3590,7 @@ static reg_extmatch_T *make_extmatch(void)
|
||||
reg_extmatch_T *em;
|
||||
|
||||
em = (reg_extmatch_T *)alloc_clear((unsigned)sizeof(reg_extmatch_T));
|
||||
if (em != NULL)
|
||||
em->refcnt = 1;
|
||||
em->refcnt = 1;
|
||||
return em;
|
||||
}
|
||||
|
||||
@@ -5699,8 +5696,6 @@ static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T e
|
||||
len += 50; /* get some extra */
|
||||
vim_free(reg_tofree);
|
||||
reg_tofree = alloc(len);
|
||||
if (reg_tofree == NULL)
|
||||
return RA_FAIL; /* out of memory!*/
|
||||
reg_tofreelen = len;
|
||||
}
|
||||
STRCPY(reg_tofree, regline);
|
||||
@@ -6451,22 +6446,20 @@ char_u *regtilde(char_u *source, int magic)
|
||||
/* length = len(newsub) - 1 + len(prev_sub) + 1 */
|
||||
prevlen = (int)STRLEN(reg_prev_sub);
|
||||
tmpsub = alloc((unsigned)(STRLEN(newsub) + prevlen));
|
||||
if (tmpsub != NULL) {
|
||||
/* copy prefix */
|
||||
len = (int)(p - newsub); /* not including ~ */
|
||||
memmove(tmpsub, newsub, (size_t)len);
|
||||
/* interpret tilde */
|
||||
memmove(tmpsub + len, reg_prev_sub, (size_t)prevlen);
|
||||
/* copy postfix */
|
||||
if (!magic)
|
||||
++p; /* back off \ */
|
||||
STRCPY(tmpsub + len + prevlen, p + 1);
|
||||
/* copy prefix */
|
||||
len = (int)(p - newsub); /* not including ~ */
|
||||
memmove(tmpsub, newsub, (size_t)len);
|
||||
/* interpret tilde */
|
||||
memmove(tmpsub + len, reg_prev_sub, (size_t)prevlen);
|
||||
/* copy postfix */
|
||||
if (!magic)
|
||||
++p; /* back off \ */
|
||||
STRCPY(tmpsub + len + prevlen, p + 1);
|
||||
|
||||
if (newsub != source) /* already allocated newsub */
|
||||
vim_free(newsub);
|
||||
newsub = tmpsub;
|
||||
p = newsub + len + prevlen;
|
||||
}
|
||||
if (newsub != source) /* already allocated newsub */
|
||||
vim_free(newsub);
|
||||
newsub = tmpsub;
|
||||
p = newsub + len + prevlen;
|
||||
} else if (magic)
|
||||
STRMOVE(p, p + 1); /* remove '~' */
|
||||
else
|
||||
@@ -6926,8 +6919,6 @@ char_u *reg_submatch(int no)
|
||||
|
||||
if (retval == NULL) {
|
||||
retval = lalloc((long_u)len, TRUE);
|
||||
if (retval == NULL)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user