changeset 25745:b916d59f259f v8.2.3408

patch 8.2.3408: can delete a numbered function Commit: https://github.com/vim/vim/commit/ddfc05100a29263a682dd96bb924dfde4354a654 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Sep 6 20:56:56 2021 +0200 patch 8.2.3408: can delete a numbered function Problem: Can delete a numbered function. (Naohiro Ono) Solution: Disallow deleting a numbered function. (closes https://github.com/vim/vim/issues/8760)
author Bram Moolenaar <Bram@vim.org>
date Mon, 06 Sep 2021 21:00:03 +0200
parents 2d28755ff4a5
children 1757d3afd6cb
files src/testdir/test_user_func.vim src/userfunc.c src/version.c
diffstat 3 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_user_func.vim
+++ b/src/testdir/test_user_func.vim
@@ -434,6 +434,11 @@ func Test_del_func()
   func d.fn()
     return 1
   endfunc
+
+  " cannot delete the dict function by number
+  let nr = substitute(execute('echo d'), '.*function(''\(\d\+\)'').*', '\1', '')
+  call assert_fails('delfunction g:' .. nr, 'E475: Invalid argument: g:')
+
   delfunc d.fn
   call assert_equal({'a' : 10}, d)
 endfunc
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -4669,6 +4669,13 @@ ex_delfunction(exarg_T *eap)
     if (eap->nextcmd != NULL)
 	*p = NUL;
 
+    if (isdigit(*name) && fudi.fd_dict == NULL)
+    {
+	if (!eap->skip)
+	    semsg(_(e_invarg2), eap->arg);
+	vim_free(name);
+	return;
+    }
     if (!eap->skip)
 	fp = find_func(name, is_global, NULL);
     vim_free(name);
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3408,
+/**/
     3407,
 /**/
     3406,