# HG changeset patch # User Bram Moolenaar # Date 1585932304 -7200 # Node ID 481e8fa158b44fb7c5c1a5b96e0a1e3059800427 # Parent e3cdf97099bbaf3a3d37d7d034769a6c72c3536b patch 8.2.0507: getbufvar() may get the wrong dictionary Commit: https://github.com/vim/vim/commit/5259275347667a90fb88d8ea74331f88ad68edfc Author: Bram Moolenaar Date: Fri Apr 3 18:43:35 2020 +0200 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 https://github.com/vim/vim/issues/5878) diff --git a/src/evalvars.c b/src/evalvars.c --- a/src/evalvars.c +++ b/src/evalvars.c @@ -2382,6 +2382,7 @@ find_var(char_u *name, hashtab_T **htp, /* * Find variable "varname" in hashtab "ht" with name "htname". + * When "varname" is empty returns curwin/curtab/etc vars dictionary. * Returns NULL if not found. */ dictitem_T * @@ -3503,8 +3504,12 @@ f_getbufvar(typval_T *argvars, typval_T else { // Look up the variable. - // Let getbufvar({nr}, "") return the "b:" dictionary. - v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', varname, FALSE); + if (*varname == NUL) + // Let getbufvar({nr}, "") return the "b:" dictionary. + v = &buf->b_bufvar; + else + v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', + varname, FALSE); if (v != NULL) { copy_tv(&v->di_tv, rettv); diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -841,6 +841,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 diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -739,6 +739,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 507, +/**/ 506, /**/ 505,