Skip to content

Commit

Permalink
patch 8.2.3408: can delete a numbered function
Browse files Browse the repository at this point in the history
Problem:    Can delete a numbered function. (Naohiro Ono)
Solution:   Disallow deleting a numbered function. (closes #8760)
  • Loading branch information
brammool committed Sep 6, 2021
1 parent 3b31851 commit ddfc051
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/testdir/test_user_func.vim
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/userfunc.c
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -755,6 +755,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3408,
/**/
3407,
/**/
Expand Down

0 comments on commit ddfc051

Please sign in to comment.