diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-04-01 01:41:39 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-06 22:54:59 -0300 |
commit | 13848aadbfed94a62505d4e349426990c75d2ae5 (patch) | |
tree | 664873759b05c4e50e879ef7630621dc023d3b56 /src/regexp.c | |
parent | 6bbffee0a5b4239e3177812c5f5f20133aa60fe8 (diff) | |
download | rneovim-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.c')
-rw-r--r-- | src/regexp.c | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/src/regexp.c b/src/regexp.c index fe496e791c..44e25856ce 100644 --- a/src/regexp.c +++ b/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); - - if (newsub != source) /* already allocated newsub */ - vim_free(newsub); - newsub = tmpsub; - p = newsub + len + prevlen; - } + /* 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; } 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 { |