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)
diff --git a/src/evalvars.c b/src/evalvars.c
index 7e40886..c4bc957 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2382,6 +2382,7 @@
/*
* 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 @@
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);