mirror of
https://github.com/neovim/neovim.git
synced 2025-10-14 05:46:12 +00:00
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)
5259275347
This commit is contained in:
@@ -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);
|
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] ht Hashtab to find variable in.
|
||||||
/// @param[in] htname Hashtab name (first character).
|
/// @param[in] htname Hashtab name (first character).
|
||||||
|
@@ -2831,7 +2831,9 @@ static void f_getbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
} else {
|
} else {
|
||||||
// Look up the variable.
|
// Look up the variable.
|
||||||
// Let getbufvar({nr}, "") return the "b:" dictionary.
|
// Let getbufvar({nr}, "") return the "b:" dictionary.
|
||||||
dictitem_T *const v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b',
|
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);
|
varname, strlen(varname), false);
|
||||||
if (v != NULL) {
|
if (v != NULL) {
|
||||||
tv_copy(&v->di_tv, rettv);
|
tv_copy(&v->di_tv, rettv);
|
||||||
|
@@ -666,6 +666,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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user