diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-04-03 20:36:11 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-04-13 12:00:34 -0400 |
commit | 572627255983b7733b6ad05da52b3e704aae8a2f (patch) | |
tree | db4262ffb11d38689dad8740a6f8264e3483ef6f | |
parent | 366e75b6be57220b28f2abc22add19d5df33b5a3 (diff) | |
download | rneovim-572627255983b7733b6ad05da52b3e704aae8a2f.tar.gz rneovim-572627255983b7733b6ad05da52b3e704aae8a2f.tar.bz2 rneovim-572627255983b7733b6ad05da52b3e704aae8a2f.zip |
vim-patch:8.2.0507: getbufvar() may get the wrong dictionary
Problem: Getbufvar() may get the wrong dictionary. (David le Blanc)
Solution: Check for empty name. (closes vim/vim#5878)
https://github.com/vim/vim/commit/5259275347667a90fb88d8ea74331f88ad68edfc
-rw-r--r-- | src/nvim/eval.c | 3 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 6 | ||||
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 10 |
3 files changed, 16 insertions, 3 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f301d29335..12b13a1f08 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -9536,7 +9536,8 @@ dictitem_T *find_var(const char *const name, const size_t name_len, return find_var_in_scoped_ht(name, name_len, no_autoload || htp != NULL); } -/// Find variable in hashtab +/// Find variable in hashtab. +/// When "varname" is empty returns curwin/curtab/etc vars dictionary. /// /// @param[in] ht Hashtab to find variable in. /// @param[in] htname Hashtab name (first character). diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 8f16855d0b..21a6904674 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2831,8 +2831,10 @@ static void f_getbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) } else { // Look up the variable. // Let getbufvar({nr}, "") return the "b:" dictionary. - dictitem_T *const v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', - varname, strlen(varname), false); + dictitem_T *const v = *varname == NUL + ? (dictitem_T *)&buf->b_bufvar + : find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', + varname, strlen(varname), false); if (v != NULL) { tv_copy(&v->di_tv, rettv); done = true; diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index b75b095841..bd5cb6ad19 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -666,6 +666,16 @@ func Test_getbufvar() call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc')) close + " Get the b: dict. + let b:testvar = 'one' + new + let b:testvar = 'two' + let thebuf = bufnr() + wincmd w + call assert_equal('two', getbufvar(thebuf, 'testvar')) + call assert_equal('two', getbufvar(thebuf, '').testvar) + bwipe! + set fileformats& endfunc |