forked from aniani/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 #5878)
This commit is contained in:
@@ -2382,6 +2382,7 @@ find_var(char_u *name, hashtab_T **htp, int no_autoload)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Find variable "varname" in hashtab "ht" with name "htname".
|
* Find variable "varname" in hashtab "ht" with name "htname".
|
||||||
|
* When "varname" is empty returns curwin/curtab/etc vars dictionary.
|
||||||
* Returns NULL if not found.
|
* Returns NULL if not found.
|
||||||
*/
|
*/
|
||||||
dictitem_T *
|
dictitem_T *
|
||||||
@@ -3503,8 +3504,12 @@ f_getbufvar(typval_T *argvars, typval_T *rettv)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Look up the variable.
|
// Look up the variable.
|
||||||
|
if (*varname == NUL)
|
||||||
// Let getbufvar({nr}, "") return the "b:" dictionary.
|
// Let getbufvar({nr}, "") return the "b:" dictionary.
|
||||||
v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', varname, FALSE);
|
v = &buf->b_bufvar;
|
||||||
|
else
|
||||||
|
v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b',
|
||||||
|
varname, FALSE);
|
||||||
if (v != NULL)
|
if (v != NULL)
|
||||||
{
|
{
|
||||||
copy_tv(&v->di_tv, rettv);
|
copy_tv(&v->di_tv, rettv);
|
||||||
|
@@ -841,6 +841,16 @@ func Test_getbufvar()
|
|||||||
call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc'))
|
call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc'))
|
||||||
close
|
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&
|
set fileformats&
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -738,6 +738,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 */
|
||||||
|
/**/
|
||||||
|
507,
|
||||||
/**/
|
/**/
|
||||||
506,
|
506,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user