summaryrefslogtreecommitdiffstats
path: root/src/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/list.c b/src/list.c
index b00ef49246..9d07b7e233 100644
--- a/src/list.c
+++ b/src/list.c
@@ -1436,15 +1436,15 @@ f_join(typval_T *argvars, typval_T *rettv)
emsg(_(e_listreq));
return;
}
+ rettv->v_type = VAR_STRING;
if (argvars[0].vval.v_list == NULL)
return;
+
if (argvars[1].v_type == VAR_UNKNOWN)
sep = (char_u *)" ";
else
sep = tv_get_string_chk(&argvars[1]);
- rettv->v_type = VAR_STRING;
-
if (sep != NULL)
{
ga_init2(&ga, (int)sizeof(char), 80);
@@ -1968,11 +1968,13 @@ do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort)
else
{
l = argvars[0].vval.v_list;
- if (l == NULL || value_check_lock(l->lv_lock,
+ if (l != NULL && value_check_lock(l->lv_lock,
(char_u *)(sort ? N_("sort() argument") : N_("uniq() argument")),
TRUE))
goto theend;
rettv_list_set(rettv, l);
+ if (l == NULL)
+ goto theend;
CHECK_LIST_MATERIALIZE(l);
len = list_len(l);
@@ -3110,32 +3112,35 @@ f_reverse(typval_T *argvars, typval_T *rettv)
if (argvars[0].v_type != VAR_LIST)
semsg(_(e_listblobarg), "reverse()");
- else if ((l = argvars[0].vval.v_list) != NULL
+ else
+ {
+ l = argvars[0].vval.v_list;
+ rettv_list_set(rettv, l);
+ if (l != NULL
&& !value_check_lock(l->lv_lock,
(char_u *)N_("reverse() argument"), TRUE))
- {
- if (l->lv_first == &range_list_item)
{
- varnumber_T new_start = l->lv_u.nonmat.lv_start
+ if (l->lv_first == &range_list_item)
+ {
+ varnumber_T new_start = l->lv_u.nonmat.lv_start
+ (l->lv_len - 1) * l->lv_u.nonmat.lv_stride;
- l->lv_u.nonmat.lv_end = new_start
+ l->lv_u.nonmat.lv_end = new_start
- (l->lv_u.nonmat.lv_end - l->lv_u.nonmat.lv_start);
- l->lv_u.nonmat.lv_start = new_start;
- l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride;
- rettv_list_set(rettv, l);
- return;
- }
- li = l->lv_u.mat.lv_last;
- l->lv_first = l->lv_u.mat.lv_last = NULL;
- l->lv_len = 0;
- while (li != NULL)
- {
- ni = li->li_prev;
- list_append(l, li);
- li = ni;
+ l->lv_u.nonmat.lv_start = new_start;
+ l->lv_u.nonmat.lv_stride = -l->lv_u.nonmat.lv_stride;
+ return;
+ }
+ li = l->lv_u.mat.lv_last;
+ l->lv_first = l->lv_u.mat.lv_last = NULL;
+ l->lv_len = 0;
+ while (li != NULL)
+ {
+ ni = li->li_prev;
+ list_append(l, li);
+ li = ni;
+ }
+ l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1;
}
- rettv_list_set(rettv, l);
- l->lv_u.mat.lv_idx = l->lv_len - l->lv_u.mat.lv_idx - 1;
}
}