mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 16:28:17 +00:00
vim-patch:8.2.0473: variables declared in an outer scope
Problem: Variables declared in an outer scope.
Solution: Decleare variables only in the scope where they are used.
8601545338
This commit is contained in:
@@ -2807,11 +2807,12 @@ static void f_getbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
buf_T *const buf = tv_get_buf(&argvars[0], false);
|
buf_T *const buf = tv_get_buf(&argvars[0], false);
|
||||||
|
|
||||||
if (buf != NULL && varname != NULL) {
|
if (buf != NULL && varname != NULL) {
|
||||||
// set curbuf to be our buf, temporarily
|
|
||||||
buf_T *const save_curbuf = curbuf;
|
|
||||||
curbuf = buf;
|
|
||||||
|
|
||||||
if (*varname == '&') { // buffer-local-option
|
if (*varname == '&') { // buffer-local-option
|
||||||
|
buf_T *const save_curbuf = curbuf;
|
||||||
|
|
||||||
|
// set curbuf to be our buf, temporarily
|
||||||
|
curbuf = buf;
|
||||||
|
|
||||||
if (varname[1] == NUL) {
|
if (varname[1] == NUL) {
|
||||||
// get all buffer-local options in a dict
|
// get all buffer-local options in a dict
|
||||||
dict_T *opts = get_winbuf_options(true);
|
dict_T *opts = get_winbuf_options(true);
|
||||||
@@ -2824,19 +2825,19 @@ static void f_getbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
// buffer-local-option
|
// buffer-local-option
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restore previous notion of curbuf
|
||||||
|
curbuf = save_curbuf;
|
||||||
} 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(&curbuf->b_vars->dv_hashtab, 'b',
|
dictitem_T *const v = 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);
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore previous notion of curbuf
|
|
||||||
curbuf = save_curbuf;
|
|
||||||
}
|
}
|
||||||
emsg_off--;
|
emsg_off--;
|
||||||
|
|
||||||
@@ -7824,10 +7825,9 @@ static void f_setbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
// reset notion of buffer
|
// reset notion of buffer
|
||||||
aucmd_restbuf(&aco);
|
aucmd_restbuf(&aco);
|
||||||
} else {
|
} else {
|
||||||
buf_T *save_curbuf = curbuf;
|
|
||||||
|
|
||||||
const size_t varname_len = STRLEN(varname);
|
const size_t varname_len = STRLEN(varname);
|
||||||
char *const bufvarname = xmalloc(varname_len + 3);
|
char *const bufvarname = xmalloc(varname_len + 3);
|
||||||
|
buf_T *const save_curbuf = curbuf;
|
||||||
curbuf = buf;
|
curbuf = buf;
|
||||||
memcpy(bufvarname, "b:", 2);
|
memcpy(bufvarname, "b:", 2);
|
||||||
memcpy(bufvarname + 2, varname, varname_len + 1);
|
memcpy(bufvarname + 2, varname, varname_len + 1);
|
||||||
|
Reference in New Issue
Block a user