mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
No OOM in dict_alloc() and rettv_dict_alloc()
This commit is contained in:
parent
8bbeb4b480
commit
c3f88060db
@ -26,6 +26,7 @@
|
|||||||
#include "nvim/ex_eval.h"
|
#include "nvim/ex_eval.h"
|
||||||
#include "nvim/ex_getln.h"
|
#include "nvim/ex_getln.h"
|
||||||
#include "nvim/fileio.h"
|
#include "nvim/fileio.h"
|
||||||
|
#include "nvim/func_attr.h"
|
||||||
#include "nvim/fold.h"
|
#include "nvim/fold.h"
|
||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/hashtab.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.
|
* 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));
|
dict_T *d = xmalloc(sizeof(dict_T));
|
||||||
|
|
||||||
@ -5614,19 +5615,14 @@ dict_T *dict_alloc(void)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate an empty dict for a return value.
|
* 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();
|
dict_T *d = dict_alloc();
|
||||||
|
|
||||||
if (d == NULL)
|
|
||||||
return FAIL;
|
|
||||||
|
|
||||||
rettv->vval.v_dict = d;
|
rettv->vval.v_dict = d;
|
||||||
rettv->v_type = VAR_DICT;
|
rettv->v_type = VAR_DICT;
|
||||||
++d->dv_refcount;
|
++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)
|
static dict_T *dict_copy(dict_T *orig, int deep, int copyID)
|
||||||
{
|
{
|
||||||
dict_T *copy;
|
|
||||||
dictitem_T *di;
|
dictitem_T *di;
|
||||||
int todo;
|
int todo;
|
||||||
hashitem_T *hi;
|
hashitem_T *hi;
|
||||||
@ -5749,8 +5744,8 @@ static dict_T *dict_copy(dict_T *orig, int deep, int copyID)
|
|||||||
if (orig == NULL)
|
if (orig == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
copy = dict_alloc();
|
dict_T *copy = dict_alloc();
|
||||||
if (copy != NULL) {
|
{
|
||||||
if (copyID != 0) {
|
if (copyID != 0) {
|
||||||
orig->dv_copyID = copyID;
|
orig->dv_copyID = copyID;
|
||||||
orig->dv_copydict = copy;
|
orig->dv_copydict = copy;
|
||||||
@ -6003,8 +5998,6 @@ static int get_dict_tv(char_u **arg, typval_T *rettv, int evaluate)
|
|||||||
|
|
||||||
if (evaluate) {
|
if (evaluate) {
|
||||||
d = dict_alloc();
|
d = dict_alloc();
|
||||||
if (d == NULL)
|
|
||||||
return FAIL;
|
|
||||||
}
|
}
|
||||||
tvkey.v_type = VAR_UNKNOWN;
|
tvkey.v_type = VAR_UNKNOWN;
|
||||||
tv.v_type = VAR_UNKNOWN;
|
tv.v_type = VAR_UNKNOWN;
|
||||||
@ -10820,8 +10813,10 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)
|
|||||||
if (rhs != NULL)
|
if (rhs != NULL)
|
||||||
rettv->vval.v_string = str2special_save(rhs, FALSE);
|
rettv->vval.v_string = str2special_save(rhs, FALSE);
|
||||||
|
|
||||||
} else if (rettv_dict_alloc(rettv) != FAIL && rhs != NULL) {
|
} else {
|
||||||
/* Return a dictionary. */
|
rettv_dict_alloc(rettv);
|
||||||
|
if (rhs != NULL) {
|
||||||
|
// Return a dictionary.
|
||||||
char_u *lhs = str2special_save(mp->m_keys, TRUE);
|
char_u *lhs = str2special_save(mp->m_keys, TRUE);
|
||||||
char_u *mapmode = map_mode_to_chars(mp->m_mode);
|
char_u *mapmode = map_mode_to_chars(mp->m_mode);
|
||||||
dict_T *dict = rettv->vval.v_dict;
|
dict_T *dict = rettv->vval.v_dict;
|
||||||
@ -10840,6 +10835,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)
|
|||||||
free(mapmode);
|
free(mapmode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "log()" function
|
* "log()" function
|
||||||
@ -14504,7 +14500,8 @@ static void f_undofile(typval_T *argvars, typval_T *rettv)
|
|||||||
*/
|
*/
|
||||||
static void f_undotree(typval_T *argvars, typval_T *rettv)
|
static void f_undotree(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
if (rettv_dict_alloc(rettv) == OK) {
|
rettv_dict_alloc(rettv);
|
||||||
|
|
||||||
dict_T *dict = rettv->vval.v_dict;
|
dict_T *dict = rettv->vval.v_dict;
|
||||||
list_T *list;
|
list_T *list;
|
||||||
|
|
||||||
@ -14522,7 +14519,6 @@ static void f_undotree(typval_T *argvars, typval_T *rettv)
|
|||||||
dict_add_list(dict, "entries", list);
|
dict_add_list(dict, "entries", list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "values(dict)" function
|
* "values(dict)" function
|
||||||
@ -14700,8 +14696,7 @@ static void f_winsaveview(typval_T *argvars, typval_T *rettv)
|
|||||||
{
|
{
|
||||||
dict_T *dict;
|
dict_T *dict;
|
||||||
|
|
||||||
if (rettv_dict_alloc(rettv) == FAIL)
|
rettv_dict_alloc(rettv);
|
||||||
return;
|
|
||||||
dict = rettv->vval.v_dict;
|
dict = rettv->vval.v_dict;
|
||||||
|
|
||||||
dict_add_nr_str(dict, "lnum", (long)curwin->w_cursor.lnum, NULL);
|
dict_add_nr_str(dict, "lnum", (long)curwin->w_cursor.lnum, NULL);
|
||||||
|
@ -3239,8 +3239,7 @@ int get_errorlist(win_T *wp, list_T *list)
|
|||||||
if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
|
if (bufnum != 0 && (buflist_findnr(bufnum) == NULL))
|
||||||
bufnum = 0;
|
bufnum = 0;
|
||||||
|
|
||||||
if ((dict = dict_alloc()) == NULL)
|
dict = dict_alloc();
|
||||||
return FAIL;
|
|
||||||
list_append_dict(list, dict);
|
list_append_dict(list, dict);
|
||||||
|
|
||||||
buf[0] = qfp->qf_type;
|
buf[0] = qfp->qf_type;
|
||||||
|
@ -784,8 +784,7 @@ do_tag (
|
|||||||
cmd[len] = NUL;
|
cmd[len] = NUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dict = dict_alloc()) == NULL)
|
dict = dict_alloc();
|
||||||
continue;
|
|
||||||
list_append_dict(list, dict);
|
list_append_dict(list, dict);
|
||||||
|
|
||||||
dict_add_nr_str(dict, "text", 0L, tag_name);
|
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)
|
if (STRNCMP(tp.tagname, "!_TAG_", 6) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((dict = dict_alloc()) == NULL)
|
dict = dict_alloc();
|
||||||
ret = FAIL;
|
|
||||||
list_append_dict(list, dict);
|
list_append_dict(list, dict);
|
||||||
|
|
||||||
full_fname = tag_full_fname(&tp);
|
full_fname = tag_full_fname(&tp);
|
||||||
|
@ -2725,8 +2725,6 @@ void u_eval_tree(u_header_T *first_uhp, list_T *list)
|
|||||||
|
|
||||||
while (uhp != NULL) {
|
while (uhp != NULL) {
|
||||||
dict = dict_alloc();
|
dict = dict_alloc();
|
||||||
if (dict == NULL)
|
|
||||||
return;
|
|
||||||
dict_add_nr_str(dict, "seq", uhp->uh_seq, NULL);
|
dict_add_nr_str(dict, "seq", uhp->uh_seq, NULL);
|
||||||
dict_add_nr_str(dict, "time", (long)uhp->uh_time, NULL);
|
dict_add_nr_str(dict, "time", (long)uhp->uh_time, NULL);
|
||||||
if (uhp == curbuf->b_u_newhead)
|
if (uhp == curbuf->b_u_newhead)
|
||||||
|
Loading…
Reference in New Issue
Block a user