aboutsummaryrefslogtreecommitdiff
path: root/src/regexp_nfa.c
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-04-01 01:41:39 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-06 22:54:59 -0300
commit13848aadbfed94a62505d4e349426990c75d2ae5 (patch)
tree664873759b05c4e50e879ef7630621dc023d3b56 /src/regexp_nfa.c
parent6bbffee0a5b4239e3177812c5f5f20133aa60fe8 (diff)
downloadrneovim-13848aadbfed94a62505d4e349426990c75d2ae5.tar.gz
rneovim-13848aadbfed94a62505d4e349426990c75d2ae5.tar.bz2
rneovim-13848aadbfed94a62505d4e349426990c75d2ae5.zip
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.
Diffstat (limited to 'src/regexp_nfa.c')
-rw-r--r--src/regexp_nfa.c32
1 files changed, 10 insertions, 22 deletions
diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index cb07272adb..52f09ebbb7 100644
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -523,18 +523,17 @@ static char_u *nfa_get_match_text(nfa_state_T *start)
return NULL;
ret = alloc(len);
- if (ret != NULL) {
- p = start->out->out; /* skip first char, it goes into regstart */
- s = ret;
- while (p->c > 0) {
- if (has_mbyte)
- s += (*mb_char2bytes)(p->c, s);
- else
- *s++ = p->c;
- p = p->out;
- }
- *s = NUL;
+ p = start->out->out; /* skip first char, it goes into regstart */
+ s = ret;
+ while (p->c > 0) {
+ if (has_mbyte)
+ s += (*mb_char2bytes)(p->c, s);
+ else
+ *s++ = p->c;
+ p = p->out;
}
+ *s = NUL;
+
return ret;
}
@@ -4219,8 +4218,6 @@ addstate_here (
l->len = l->len * 3 / 2 + 50;
newl = (nfa_thread_T *)alloc(l->len * sizeof(nfa_thread_T));
- if (newl == NULL)
- return;
memmove(&(newl[0]),
&(l->t[0]),
sizeof(nfa_thread_T) * listidx);
@@ -4550,10 +4547,6 @@ static int recursive_regmatch(nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T
* values and clear them. */
if (*listids == NULL) {
*listids = (int *)lalloc(sizeof(int) * nstate, TRUE);
- if (*listids == NULL) {
- EMSG(_("E878: (NFA) Could not allocate memory for branch traversal!"));
- return 0;
- }
}
nfa_save_listids(prog, *listids);
need_restore = TRUE;
@@ -4885,8 +4878,6 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
list[0].len = nstate + 1;
list[1].t = (nfa_thread_T *)lalloc(size, TRUE);
list[1].len = nstate + 1;
- if (list[0].t == NULL || list[1].t == NULL)
- goto theend;
#ifdef ENABLE_LOG
log_fd = fopen(NFA_REGEXP_RUN_LOG, "a");
@@ -6037,7 +6028,6 @@ nextchar:
log_fd = NULL;
#endif
-theend:
/* Free memory */
vim_free(list[0].t);
vim_free(list[1].t);
@@ -6314,8 +6304,6 @@ static regprog_T *nfa_regcomp(char_u *expr, int re_flags)
/* allocate the regprog with space for the compiled regexp */
prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1);
prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
- if (prog == NULL)
- goto fail;
state_ptr = prog->state;
/*