changeset 29138:175eacde28b8 v8.2.5089

patch 8.2.5089: some functions return a different value on failure Commit: https://github.com/vim/vim/commit/ca195cc84fb3f5e497cdbc5f1f53dc1d7efedf48 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Jun 14 13:42:26 2022 +0100 patch 8.2.5089: some functions return a different value on failure Problem: Some functions return a different value on failure. Solution: Initialize the return value earlier. (Yegappan Lakshmanan, closes #10568)
author Bram Moolenaar <Bram@vim.org>
date Tue, 14 Jun 2022 14:45:07 +0200
parents 88d66707bf3f
children 28ec71e8068d
files src/autocmd.c src/dict.c src/evalfunc.c src/list.c src/version.c
diffstat 5 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -3062,6 +3062,8 @@ f_autocmd_get(typval_T *argvars, typval_
     char_u	*name = NULL;
     int		group = AUGROUP_ALL;
 
+    if (rettv_list_alloc(rettv) == FAIL)
+	return;
     if (check_for_opt_dict_arg(argvars, 0) == FAIL)
 	return;
 
@@ -3128,8 +3130,6 @@ f_autocmd_get(typval_T *argvars, typval_
 	}
     }
 
-    if (rettv_list_alloc(rettv) == FAIL)
-	return;
     event_list = rettv->vval.v_list;
 
     // iterate through all the autocmd events
--- a/src/dict.c
+++ b/src/dict.c
@@ -1457,6 +1457,9 @@ dict_list(typval_T *argvars, typval_T *r
     dict_T	*d;
     int		todo;
 
+    if (rettv_list_alloc(rettv) == FAIL)
+	return;
+
     if (in_vim9script() && check_for_dict_arg(argvars, 0) == FAIL)
 	return;
 
@@ -1466,8 +1469,6 @@ dict_list(typval_T *argvars, typval_T *r
 	return;
     }
 
-    if (rettv_list_alloc(rettv) == FAIL)
-	return;
     if ((d = argvars[0].vval.v_dict) == NULL)
 	// empty dict behaves like an empty dict
 	return;
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -8133,6 +8133,9 @@ f_range(typval_T *argvars, typval_T *ret
     varnumber_T	stride = 1;
     int		error = FALSE;
 
+    if (rettv_list_alloc(rettv) != OK)
+	return;
+
     if (in_vim9script()
 	    && (check_for_number_arg(argvars, 0) == FAIL
 		|| check_for_opt_number_arg(argvars, 1) == FAIL
@@ -8159,7 +8162,7 @@ f_range(typval_T *argvars, typval_T *ret
 	emsg(_(e_stride_is_zero));
     else if (stride > 0 ? end + 1 < start : end - 1 > start)
 	emsg(_(e_start_past_end));
-    else if (rettv_list_alloc(rettv) == OK)
+    else
     {
 	list_T *list = rettv->vval.v_list;
 
--- a/src/list.c
+++ b/src/list.c
@@ -1440,6 +1440,8 @@ f_join(typval_T *argvars, typval_T *rett
     garray_T	ga;
     char_u	*sep;
 
+    rettv->v_type = VAR_STRING;
+
     if (in_vim9script()
 	    && (check_for_list_arg(argvars, 0) == FAIL
 		|| check_for_opt_string_arg(argvars, 1) == FAIL))
@@ -1450,7 +1452,7 @@ f_join(typval_T *argvars, typval_T *rett
 	emsg(_(e_list_required));
 	return;
     }
-    rettv->v_type = VAR_STRING;
+
     if (argvars[0].vval.v_list == NULL)
 	return;
 
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    5089,
+/**/
     5088,
 /**/
     5087,