diff src/evalfunc.c @ 26585:0d2a709e2ff0 v8.2.3822

patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9 Commit: https://github.com/vim/vim/commit/2d877599ee1cede063ef4abe3a2272e67c116238 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Dec 16 08:21:09 2021 +0000 patch 8.2.3822: leaking memory in map() and filter(), no string in Vim9 Problem: Leaking memory in map() and filter(), cannot use a string argument in Vim9 script. Solution: Fix the leak, adjust the argument check, also run the tests as Vim9 script. (Yegappan Lakshmanan, closes #9354)
author Bram Moolenaar <Bram@vim.org>
date Thu, 16 Dec 2021 09:30:04 +0100
parents 255bc9a08e58
children fac6673086df
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -449,6 +449,22 @@ arg_list_or_dict_or_blob(type_T *type, a
 }
 
 /*
+ * Check "type" is a list of 'any' or a dict of 'any' or a blob or a string.
+ */
+    static int
+arg_list_or_dict_or_blob_or_string(type_T *type, argcontext_T *context)
+{
+    if (type->tt_type == VAR_ANY
+		     || type->tt_type == VAR_LIST
+		     || type->tt_type == VAR_DICT
+		     || type->tt_type == VAR_BLOB
+		     || type->tt_type == VAR_STRING)
+	return OK;
+    arg_type_mismatch(&t_list_any, type, context->arg_idx + 1);
+    return FAIL;
+}
+
+/*
  * Check "type" is a job.
  */
     static int
@@ -797,7 +813,7 @@ static argcheck_T arg23_insert[] = {arg_
 static argcheck_T arg1_len[] = {arg_len1};
 static argcheck_T arg3_libcall[] = {arg_string, arg_string, arg_string_or_nr};
 static argcheck_T arg14_maparg[] = {arg_string, arg_string, arg_bool, arg_bool};
-static argcheck_T arg2_mapfilter[] = {arg_list_or_dict_or_blob, NULL};
+static argcheck_T arg2_mapfilter[] = {arg_list_or_dict_or_blob_or_string, NULL};
 static argcheck_T arg25_matchadd[] = {arg_string, arg_string, arg_number, arg_number, arg_dict_any};
 static argcheck_T arg25_matchaddpos[] = {arg_string, arg_list_any, arg_number, arg_number, arg_dict_any};
 static argcheck_T arg119_printf[] = {arg_string_or_nr, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};