Call to list_append_tv cannot fail.

Clean up the use of list_append_tv and remove error checks.
This commit is contained in:
oni-link 2014-04-24 21:38:46 +02:00 committed by Thiago de Arruda
parent 6797a3e788
commit dc9b680deb
2 changed files with 8 additions and 15 deletions

View File

@ -4759,12 +4759,9 @@ eval_index (
l = list_alloc(); l = list_alloc();
if (l == NULL) if (l == NULL)
return FAIL; return FAIL;
for (item = list_find(rettv->vval.v_list, n1); item = list_find(rettv->vval.v_list, n1);
n1 <= n2; ++n1) { while (n1++ <= n2) {
if (list_append_tv(l, &item->li_tv) == FAIL) { list_append_tv(l, &item->li_tv);
list_free(l, TRUE);
return FAIL;
}
item = item->li_next; item = item->li_next;
} }
clear_tv(rettv); clear_tv(rettv);
@ -5517,17 +5514,12 @@ void list_append(list_T *l, listitem_T *item)
/* /*
* Append typval_T "tv" to the end of list "l". * Append typval_T "tv" to the end of list "l".
* Return FAIL when out of memory.
*/ */
int list_append_tv(list_T *l, typval_T *tv) void list_append_tv(list_T *l, typval_T *tv)
{ {
listitem_T *li = listitem_alloc(); listitem_T *li = listitem_alloc();
if (li == NULL)
return FAIL;
copy_tv(tv, &li->li_tv); copy_tv(tv, &li->li_tv);
list_append(l, li); list_append(l, li);
return OK;
} }
/* /*
@ -7534,9 +7526,10 @@ static void f_add(typval_T *argvars, typval_T *rettv)
rettv->vval.v_number = 1; /* Default: Failed */ rettv->vval.v_number = 1; /* Default: Failed */
if (argvars[0].v_type == VAR_LIST) { if (argvars[0].v_type == VAR_LIST) {
if ((l = argvars[0].vval.v_list) != NULL if ((l = argvars[0].vval.v_list) != NULL
&& !tv_check_lock(l->lv_lock, (char_u *)_("add() argument")) && !tv_check_lock(l->lv_lock, (char_u *)_("add() argument"))) {
&& list_append_tv(l, &argvars[1]) == OK) list_append_tv(l, &argvars[1]);
copy_tv(&argvars[0], rettv); copy_tv(&argvars[0], rettv);
}
} else } else
EMSG(_(e_listreq)); EMSG(_(e_listreq));
} }

View File

@ -63,7 +63,7 @@ dictitem_T *dict_lookup(hashitem_T *hi);
listitem_T *list_find(list_T *l, long n); listitem_T *list_find(list_T *l, long n);
char_u *list_find_str(list_T *l, long idx); char_u *list_find_str(list_T *l, long idx);
void list_append(list_T *l, listitem_T *item); void list_append(list_T *l, listitem_T *item);
int list_append_tv(list_T *l, typval_T *tv); void list_append_tv(list_T *l, typval_T *tv);
void list_append_dict(list_T *list, dict_T *dict); void list_append_dict(list_T *list, dict_T *dict);
void list_append_string(list_T *l, char_u *str, int len); void list_append_string(list_T *l, char_u *str, int len);
int list_insert_tv(list_T *l, typval_T *tv, listitem_T *item); int list_insert_tv(list_T *l, typval_T *tv, listitem_T *item);