aboutsummaryrefslogtreecommitdiff
path: root/src/getchar.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/getchar.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/getchar.c')
-rw-r--r--src/getchar.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/getchar.c b/src/getchar.c
index 62110d90d2..19892b6980 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -197,7 +197,8 @@ static char_u *get_buffcont(buffheader_T *buffer,
for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
count += (long_u)STRLEN(bp->b_str);
- if ((count || dozero) && (p = lalloc(count + 1, TRUE)) != NULL) {
+ if (count || dozero) {
+ p = lalloc(count + 1, TRUE);
p2 = p;
for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
for (str = bp->b_str; *str; )
@@ -290,8 +291,6 @@ add_buff (
else
len = slen;
p = (buffblock_T *)lalloc((long_u)(sizeof(buffblock_T) + len), TRUE);
- if (p == NULL)
- return; /* no space, just forget it */
buf->bh_space = (int)(len - slen);
vim_strncpy(p->b_str, s, (size_t)slen);
@@ -3827,30 +3826,29 @@ char_u *vim_strsave_escape_csi(char_u *p)
/* Need a buffer to hold up to three times as much. */
res = alloc((unsigned)(STRLEN(p) * 3) + 1);
- if (res != NULL) {
- d = res;
- for (s = p; *s != NUL; ) {
- if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) {
- /* Copy special key unmodified. */
- *d++ = *s++;
- *d++ = *s++;
- *d++ = *s++;
- } else {
- int len = mb_char2len(PTR2CHAR(s));
- int len2 = mb_ptr2len(s);
- /* Add character, possibly multi-byte to destination, escaping
- * CSI and K_SPECIAL. */
- d = add_char2buf(PTR2CHAR(s), d);
- while (len < len2) {
- /* add following combining char */
- d = add_char2buf(PTR2CHAR(s + len), d);
- len += mb_char2len(PTR2CHAR(s + len));
- }
- mb_ptr_adv(s);
+ d = res;
+ for (s = p; *s != NUL; ) {
+ if (s[0] == K_SPECIAL && s[1] != NUL && s[2] != NUL) {
+ /* Copy special key unmodified. */
+ *d++ = *s++;
+ *d++ = *s++;
+ *d++ = *s++;
+ } else {
+ int len = mb_char2len(PTR2CHAR(s));
+ int len2 = mb_ptr2len(s);
+ /* Add character, possibly multi-byte to destination, escaping
+ * CSI and K_SPECIAL. */
+ d = add_char2buf(PTR2CHAR(s), d);
+ while (len < len2) {
+ /* add following combining char */
+ d = add_char2buf(PTR2CHAR(s + len), d);
+ len += mb_char2len(PTR2CHAR(s + len));
}
+ mb_ptr_adv(s);
}
- *d = NUL;
}
+ *d = NUL;
+
return res;
}