1
0
forked from aniani/vim

patch 8.2.3408: can delete a numbered function

Problem:    Can delete a numbered function. (Naohiro Ono)
Solution:   Disallow deleting a numbered function. (closes #8760)
This commit is contained in:
Bram Moolenaar
2021-09-06 20:56:56 +02:00
parent 3b31851356
commit ddfc05100a
3 changed files with 14 additions and 0 deletions

View File

@@ -434,6 +434,11 @@ func Test_del_func()
func d.fn() func d.fn()
return 1 return 1
endfunc 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 delfunc d.fn
call assert_equal({'a' : 10}, d) call assert_equal({'a' : 10}, d)
endfunc endfunc

View File

@@ -4669,6 +4669,13 @@ ex_delfunction(exarg_T *eap)
if (eap->nextcmd != NULL) if (eap->nextcmd != NULL)
*p = NUL; *p = NUL;
if (isdigit(*name) && fudi.fd_dict == NULL)
{
if (!eap->skip)
semsg(_(e_invarg2), eap->arg);
vim_free(name);
return;
}
if (!eap->skip) if (!eap->skip)
fp = find_func(name, is_global, NULL); fp = find_func(name, is_global, NULL);
vim_free(name); vim_free(name);

View File

@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3408,
/**/ /**/
3407, 3407,
/**/ /**/