aboutsummaryrefslogtreecommitdiff
path: root/src/message.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/message.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/message.c')
-rw-r--r--src/message.c83
1 files changed, 37 insertions, 46 deletions
diff --git a/src/message.c b/src/message.c
index 6ee608861f..57942de2c6 100644
--- a/src/message.c
+++ b/src/message.c
@@ -239,8 +239,7 @@ msg_strtrunc (
else
len = room + 2;
buf = alloc(len);
- if (buf != NULL)
- trunc_string(s, buf, room, len);
+ trunc_string(s, buf, room, len);
}
}
return buf;
@@ -394,8 +393,7 @@ static char_u *get_emsg_source(void)
if (sourcing_name != NULL && other_sourcing_name()) {
p = (char_u *)_("Error detected while processing %s:");
Buf = alloc((unsigned)(STRLEN(sourcing_name) + STRLEN(p)));
- if (Buf != NULL)
- sprintf((char *)Buf, (char *)p, sourcing_name);
+ sprintf((char *)Buf, (char *)p, sourcing_name);
return Buf;
}
return NULL;
@@ -417,8 +415,7 @@ static char_u *get_emsg_lnum(void)
&& sourcing_lnum != 0) {
p = (char_u *)_("line %4ld:");
Buf = alloc((unsigned)(STRLEN(p) + 20));
- if (Buf != NULL)
- sprintf((char *)Buf, (char *)p, (long)sourcing_lnum);
+ sprintf((char *)Buf, (char *)p, (long)sourcing_lnum);
return Buf;
}
return NULL;
@@ -665,26 +662,24 @@ add_msg_hist (
/* allocate an entry and add the message at the end of the history */
p = (struct msg_hist *)alloc((int)sizeof(struct msg_hist));
- if (p != NULL) {
- if (len < 0)
- len = (int)STRLEN(s);
- /* remove leading and trailing newlines */
- while (len > 0 && *s == '\n') {
- ++s;
- --len;
- }
- while (len > 0 && s[len - 1] == '\n')
- --len;
- p->msg = vim_strnsave(s, len);
- p->next = NULL;
- p->attr = attr;
- if (last_msg_hist != NULL)
- last_msg_hist->next = p;
- last_msg_hist = p;
- if (first_msg_hist == NULL)
- first_msg_hist = last_msg_hist;
- ++msg_hist_len;
- }
+ if (len < 0)
+ len = (int)STRLEN(s);
+ /* remove leading and trailing newlines */
+ while (len > 0 && *s == '\n') {
+ ++s;
+ --len;
+ }
+ while (len > 0 && s[len - 1] == '\n')
+ --len;
+ p->msg = vim_strnsave(s, len);
+ p->next = NULL;
+ p->attr = attr;
+ if (last_msg_hist != NULL)
+ last_msg_hist->next = p;
+ last_msg_hist = p;
+ if (first_msg_hist == NULL)
+ first_msg_hist = last_msg_hist;
+ ++msg_hist_len;
}
/*
@@ -1818,11 +1813,9 @@ static void inc_msg_scrolled(void)
else {
len = (int)STRLEN(p) + 40;
tofree = alloc(len);
- if (tofree != NULL) {
- vim_snprintf((char *)tofree, len, _("%s line %ld"),
- p, (long)sourcing_lnum);
- p = tofree;
- }
+ vim_snprintf((char *)tofree, len, _("%s line %ld"),
+ p, (long)sourcing_lnum);
+ p = tofree;
}
set_vim_var_string(VV_SCROLLSTART, p, -1);
vim_free(tofree);
@@ -1872,22 +1865,20 @@ store_sb_text (
if (s > *sb_str) {
mp = (msgchunk_T *)alloc((int)(sizeof(msgchunk_T) + (s - *sb_str)));
- if (mp != NULL) {
- mp->sb_eol = finish;
- mp->sb_msg_col = *sb_col;
- mp->sb_attr = attr;
- vim_strncpy(mp->sb_text, *sb_str, s - *sb_str);
-
- if (last_msgchunk == NULL) {
- last_msgchunk = mp;
- mp->sb_prev = NULL;
- } else {
- mp->sb_prev = last_msgchunk;
- last_msgchunk->sb_next = mp;
- last_msgchunk = mp;
- }
- mp->sb_next = NULL;
+ mp->sb_eol = finish;
+ mp->sb_msg_col = *sb_col;
+ mp->sb_attr = attr;
+ vim_strncpy(mp->sb_text, *sb_str, s - *sb_str);
+
+ if (last_msgchunk == NULL) {
+ last_msgchunk = mp;
+ mp->sb_prev = NULL;
+ } else {
+ mp->sb_prev = last_msgchunk;
+ last_msgchunk->sb_next = mp;
+ last_msgchunk = mp;
}
+ mp->sb_next = NULL;
} else if (finish && last_msgchunk != NULL)
last_msgchunk->sb_eol = TRUE;