mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
coverity/155513: Do not assume xcalloc can return NULL
This commit is contained in:
parent
043d8ba422
commit
47a7d32563
@ -9748,34 +9748,28 @@ static void f_function(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dict_idx > 0 || arg_idx > 0 || arg_pt != NULL) {
|
if (dict_idx > 0 || arg_idx > 0 || arg_pt != NULL) {
|
||||||
partial_T *pt = (partial_T *)xcalloc(1, sizeof(partial_T));
|
partial_T *const pt = xcalloc(1, sizeof(*pt));
|
||||||
|
|
||||||
// result is a VAR_PARTIAL
|
// result is a VAR_PARTIAL
|
||||||
if (pt != NULL) {
|
|
||||||
if (arg_idx > 0 || (arg_pt != NULL && arg_pt->pt_argc > 0)) {
|
if (arg_idx > 0 || (arg_pt != NULL && arg_pt->pt_argc > 0)) {
|
||||||
listitem_T *li;
|
const int arg_len = (arg_pt == NULL ? 0 : arg_pt->pt_argc);
|
||||||
int i = 0;
|
const int lv_len = (list == NULL ? 0 : list->lv_len);
|
||||||
int arg_len = 0;
|
|
||||||
int lv_len = 0;
|
|
||||||
|
|
||||||
if (arg_pt != NULL) {
|
|
||||||
arg_len = arg_pt->pt_argc;
|
|
||||||
}
|
|
||||||
if (list != NULL) {
|
|
||||||
lv_len = list->lv_len;
|
|
||||||
}
|
|
||||||
pt->pt_argc = arg_len + lv_len;
|
pt->pt_argc = arg_len + lv_len;
|
||||||
pt->pt_argv = (typval_T *)xmalloc(sizeof(typval_T) * pt->pt_argc);
|
pt->pt_argv = xmalloc(sizeof(pt->pt_argv[0]) * pt->pt_argc);
|
||||||
if (pt->pt_argv == NULL) {
|
if (pt->pt_argv == NULL) {
|
||||||
xfree(pt);
|
xfree(pt);
|
||||||
xfree(name);
|
xfree(name);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < arg_len; i++) {
|
int i = 0;
|
||||||
|
for (; i < arg_len; i++) {
|
||||||
copy_tv(&arg_pt->pt_argv[i], &pt->pt_argv[i]);
|
copy_tv(&arg_pt->pt_argv[i], &pt->pt_argv[i]);
|
||||||
}
|
}
|
||||||
if (lv_len > 0) {
|
if (lv_len > 0) {
|
||||||
for (li = list->lv_first; li != NULL; li = li->li_next) {
|
for (listitem_T *li = list->lv_first;
|
||||||
|
li != NULL;
|
||||||
|
li = li->li_next) {
|
||||||
copy_tv(&li->li_tv, &pt->pt_argv[i++]);
|
copy_tv(&li->li_tv, &pt->pt_argv[i++]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9801,7 +9795,7 @@ static void f_function(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
pt->pt_refcount = 1;
|
pt->pt_refcount = 1;
|
||||||
pt->pt_name = name;
|
pt->pt_name = name;
|
||||||
func_ref(pt->pt_name);
|
func_ref(pt->pt_name);
|
||||||
}
|
|
||||||
rettv->v_type = VAR_PARTIAL;
|
rettv->v_type = VAR_PARTIAL;
|
||||||
rettv->vval.v_partial = pt;
|
rettv->vval.v_partial = pt;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user