From 1aad5af637b0fc042e1155cc0955931e9ca75295 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Dec 2022 20:44:26 +0800 Subject: vim-patch:8.2.3829: no error when setting a func option to script-local function Problem: No error when setting a func option to a script-local function. Solution: Give an error if the name starts with "s:". (closes vim/vim#9358) https://github.com/vim/vim/commit/94c785d235dccacf6cdf38c5903115b61ca8a981 Omit test: reverted in patch 8.2.3838. Cherry-pick SCRIPT_ID_VALID from patch 8.2.1539. Co-authored-by: Bram Moolenaar --- src/nvim/option.c | 4 ++++ src/nvim/runtime.h | 1 + src/nvim/testdir/test_tagfunc.vim | 2 ++ 3 files changed, 7 insertions(+) (limited to 'src') diff --git a/src/nvim/option.c b/src/nvim/option.c index e67bacce61..72090fdbcc 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5157,6 +5157,10 @@ int option_set_callback_func(char *optval, Callback *optcb) return OK; } + if (strncmp(optval, "s:", 2) == 0 && !SCRIPT_ID_VALID(current_sctx.sc_sid)) { + return FAIL; + } + typval_T *tv; if (*optval == '{' || (strncmp(optval, "function(", 9) == 0) diff --git a/src/nvim/runtime.h b/src/nvim/runtime.h index d40bb6c1c1..de363020f8 100644 --- a/src/nvim/runtime.h +++ b/src/nvim/runtime.h @@ -79,6 +79,7 @@ typedef struct scriptitem_S { /// Growarray to store info about already sourced scripts. extern garray_T script_items; #define SCRIPT_ITEM(id) (((scriptitem_T *)script_items.ga_data)[(id) - 1]) +#define SCRIPT_ID_VALID(id) ((id) > 0 && (id) <= script_items.ga_len) typedef void (*DoInRuntimepathCB)(char *, void *); diff --git a/src/nvim/testdir/test_tagfunc.vim b/src/nvim/testdir/test_tagfunc.vim index 7a88723bc0..9b4a550945 100644 --- a/src/nvim/testdir/test_tagfunc.vim +++ b/src/nvim/testdir/test_tagfunc.vim @@ -1,6 +1,8 @@ " Test 'tagfunc' source vim9.vim +source check.vim +source screendump.vim func TagFunc(pat, flag, info) let g:tagfunc_args = [a:pat, a:flag, a:info] -- cgit