aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-05-28 18:01:15 -0300
committerFelipe Oliveira Carvalho <felipekde@gmail.com>2014-06-16 01:31:34 -0300
commitc3f88060db0d5cd3124a580e0c2af7957d1d0912 (patch)
treea505c5ff8c484f7a71e188331a0c466598d560af /src
parent8bbeb4b480a72d0099a18c4d8200313600045231 (diff)
downloadrneovim-c3f88060db0d5cd3124a580e0c2af7957d1d0912.tar.gz
rneovim-c3f88060db0d5cd3124a580e0c2af7957d1d0912.tar.bz2
rneovim-c3f88060db0d5cd3124a580e0c2af7957d1d0912.zip
No OOM in dict_alloc() and rettv_dict_alloc()
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c87
-rw-r--r--src/nvim/quickfix.c3
-rw-r--r--src/nvim/tag.c6
-rw-r--r--src/nvim/undo.c2
4 files changed, 44 insertions, 54 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index e4e90142cc..8a2f1520e1 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -26,6 +26,7 @@
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
+#include "nvim/func_attr.h"
#include "nvim/fold.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
@@ -5592,7 +5593,7 @@ void set_ref_in_item(typval_T *tv, int copyID)
/*
* Allocate an empty header for a dictionary.
*/
-dict_T *dict_alloc(void)
+dict_T *dict_alloc(void) FUNC_ATTR_NONNULL_RET
{
dict_T *d = xmalloc(sizeof(dict_T));
@@ -5614,19 +5615,14 @@ dict_T *dict_alloc(void)
/*
* Allocate an empty dict for a return value.
- * Returns OK or FAIL.
*/
-static int rettv_dict_alloc(typval_T *rettv)
+static void rettv_dict_alloc(typval_T *rettv)
{
- dict_T *d = dict_alloc();
-
- if (d == NULL)
- return FAIL;
+ dict_T *d = dict_alloc();
rettv->vval.v_dict = d;
rettv->v_type = VAR_DICT;
++d->dv_refcount;
- return OK;
}
@@ -5741,7 +5737,6 @@ void dictitem_free(dictitem_T *item)
*/
static dict_T *dict_copy(dict_T *orig, int deep, int copyID)
{
- dict_T *copy;
dictitem_T *di;
int todo;
hashitem_T *hi;
@@ -5749,8 +5744,8 @@ static dict_T *dict_copy(dict_T *orig, int deep, int copyID)
if (orig == NULL)
return NULL;
- copy = dict_alloc();
- if (copy != NULL) {
+ dict_T *copy = dict_alloc();
+ {
if (copyID != 0) {
orig->dv_copyID = copyID;
orig->dv_copydict = copy;
@@ -6003,8 +5998,6 @@ static int get_dict_tv(char_u **arg, typval_T *rettv, int evaluate)
if (evaluate) {
d = dict_alloc();
- if (d == NULL)
- return FAIL;
}
tvkey.v_type = VAR_UNKNOWN;
tv.v_type = VAR_UNKNOWN;
@@ -10820,24 +10813,27 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)
if (rhs != NULL)
rettv->vval.v_string = str2special_save(rhs, FALSE);
- } else if (rettv_dict_alloc(rettv) != FAIL && rhs != NULL) {
- /* Return a dictionary. */
- char_u *lhs = str2special_save(mp->m_keys, TRUE);
- char_u *mapmode = map_mode_to_chars(mp->m_mode);
- dict_T *dict = rettv->vval.v_dict;
+ } else {
+ rettv_dict_alloc(rettv);
+ if (rhs != NULL) {
+ // Return a dictionary.
+ char_u *lhs = str2special_save(mp->m_keys, TRUE);
+ char_u *mapmode = map_mode_to_chars(mp->m_mode);
+ dict_T *dict = rettv->vval.v_dict;
- dict_add_nr_str(dict, "lhs", 0L, lhs);
- dict_add_nr_str(dict, "rhs", 0L, mp->m_orig_str);
- dict_add_nr_str(dict, "noremap", mp->m_noremap ? 1L : 0L, NULL);
- dict_add_nr_str(dict, "expr", mp->m_expr ? 1L : 0L, NULL);
- dict_add_nr_str(dict, "silent", mp->m_silent ? 1L : 0L, NULL);
- dict_add_nr_str(dict, "sid", (long)mp->m_script_ID, NULL);
- dict_add_nr_str(dict, "buffer", (long)buffer_local, NULL);
- dict_add_nr_str(dict, "nowait", mp->m_nowait ? 1L : 0L, NULL);
- dict_add_nr_str(dict, "mode", 0L, mapmode);
+ dict_add_nr_str(dict, "lhs", 0L, lhs);
+ dict_add_nr_str(dict, "rhs", 0L, mp->m_orig_str);
+ dict_add_nr_str(dict, "noremap", mp->m_noremap ? 1L : 0L, NULL);
+ dict_add_nr_str(dict, "expr", mp->m_expr ? 1L : 0L, NULL);
+ dict_add_nr_str(dict, "silent", mp->m_silent ? 1L : 0L, NULL);
+ dict_add_nr_str(dict, "sid", (long)mp->m_script_ID, NULL);
+ dict_add_nr_str(dict, "buffer", (long)buffer_local, NULL);
+ dict_add_nr_str(dict, "nowait", mp->m_nowait ? 1L : 0L, NULL);
+ dict_add_nr_str(dict, "mode", 0L, mapmode);
- free(lhs);
- free(mapmode);
+ free(lhs);
+ free(mapmode);
+ }
}
}
@@ -14504,23 +14500,23 @@ static void f_undofile(typval_T *argvars, typval_T *rettv)
*/
static void f_undotree(typval_T *argvars, typval_T *rettv)
{
- if (rettv_dict_alloc(rettv) == OK) {
- dict_T *dict = rettv->vval.v_dict;
- list_T *list;
+ rettv_dict_alloc(rettv);
- dict_add_nr_str(dict, "synced", (long)curbuf->b_u_synced, NULL);
- dict_add_nr_str(dict, "seq_last", curbuf->b_u_seq_last, NULL);
- dict_add_nr_str(dict, "save_last",
- (long)curbuf->b_u_save_nr_last, NULL);
- dict_add_nr_str(dict, "seq_cur", curbuf->b_u_seq_cur, NULL);
- dict_add_nr_str(dict, "time_cur", (long)curbuf->b_u_time_cur, NULL);
- dict_add_nr_str(dict, "save_cur", (long)curbuf->b_u_save_nr_cur, NULL);
+ dict_T *dict = rettv->vval.v_dict;
+ list_T *list;
- list = list_alloc();
- if (list != NULL) {
- u_eval_tree(curbuf->b_u_oldhead, list);
- dict_add_list(dict, "entries", list);
- }
+ dict_add_nr_str(dict, "synced", (long)curbuf->b_u_synced, NULL);
+ dict_add_nr_str(dict, "seq_last", curbuf->b_u_seq_last, NULL);
+ dict_add_nr_str(dict, "save_last",
+ (long)curbuf->b_u_save_nr_last, NULL);
+ dict_add_nr_str(dict, "seq_cur", curbuf->b_u_seq_cur, NULL);
+ dict_add_nr_str(dict, "time_cur", (long)curbuf->b_u_time_cur, NULL);
+ dict_add_nr_str(dict, "save_cur", (long)curbuf->b_u_save_nr_cur, NULL);
+
+ list = list_alloc();
+ if (list != NULL) {
+ u_eval_tree(curbuf->b_u_oldhead, list);
+ dict_add_list(dict, "entries", list);
}
}
@@ -14700,8 +14696,7 @@ static void f_winsaveview(typval_T *argvars, typval_T *rettv)
{
dict_T *dict;
- if (rettv_dict_alloc(rettv) == FAIL)
- return;
+ rettv_dict_alloc(rettv);
dict = rettv->vval.v_dict;
dict_add_nr_str(dict, "lnum", (long)curwin->w_cursor.lnum, NULL);
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 0e40b8eb3e..492ac1e606 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -3239,8 +3239,7 @@ int get_errorlist(win_T *wp, list_T *list)
if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
bufnum = 0;
- if ((dict = dict_alloc()) == NULL)
- return FAIL;
+ dict = dict_alloc();
list_append_dict(list, dict);
buf[0] = qfp->qf_type;
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index 40611bd237..c9a065391b 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -784,8 +784,7 @@ do_tag (
cmd[len] = NUL;
}
- if ((dict = dict_alloc()) == NULL)
- continue;
+ dict = dict_alloc();
list_append_dict(list, dict);
dict_add_nr_str(dict, "text", 0L, tag_name);
@@ -2822,8 +2821,7 @@ int get_tags(list_T *list, char_u *pat)
if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0)
continue;
- if ((dict = dict_alloc()) == NULL)
- ret = FAIL;
+ dict = dict_alloc();
list_append_dict(list, dict);
full_fname = tag_full_fname(&tp);
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index b7a3601d0f..5d8fb4d5e1 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -2725,8 +2725,6 @@ void u_eval_tree(u_header_T *first_uhp, list_T *list)
while (uhp != NULL) {
dict = dict_alloc();
- if (dict == NULL)
- return;
dict_add_nr_str(dict, "seq", uhp->uh_seq, NULL);
dict_add_nr_str(dict, "time", (long)uhp->uh_time, NULL);
if (uhp == curbuf->b_u_newhead)