diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-03-29 15:12:15 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-03-29 15:12:15 +0200 |
commit | 8601545338581c01e328cdc3a72c0b12d92c54cf (patch) | |
tree | 78d5007c98b2209e79775833915fec826d325f61 | |
parent | 360bdbda817920657a2ec8bf329c96a749dd7224 (diff) | |
download | vim-git-8601545338581c01e328cdc3a72c0b12d92c54cf.tar.gz |
patch 8.2.0473: variables declared in an outer scopev8.2.0473
Problem: Variables declared in an outer scope.
Solution: Decleare variables only in the scope where they are used.
-rw-r--r-- | src/evalvars.c | 23 | ||||
-rw-r--r-- | src/version.c | 2 |
2 files changed, 13 insertions, 12 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index 40a22f690..0ffff5686 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -3461,7 +3461,6 @@ f_getwinvar(typval_T *argvars, typval_T *rettv) f_getbufvar(typval_T *argvars, typval_T *rettv) { buf_T *buf; - buf_T *save_curbuf; char_u *varname; dictitem_T *v; int done = FALSE; @@ -3476,12 +3475,13 @@ f_getbufvar(typval_T *argvars, typval_T *rettv) if (buf != NULL && varname != NULL) { - // set curbuf to be our buf, temporarily - save_curbuf = curbuf; - curbuf = buf; - if (*varname == '&') { + buf_T *save_curbuf = curbuf; + + // set curbuf to be our buf, temporarily + curbuf = buf; + if (varname[1] == NUL) { // get all buffer-local options in a dict @@ -3496,22 +3496,21 @@ f_getbufvar(typval_T *argvars, typval_T *rettv) else if (get_option_tv(&varname, rettv, TRUE) == OK) // buffer-local-option done = TRUE; + + // restore previous notion of curbuf + curbuf = save_curbuf; } else { // Look up the variable. // Let getbufvar({nr}, "") return the "b:" dictionary. - v = find_var_in_ht(&curbuf->b_vars->dv_hashtab, - 'b', varname, FALSE); + v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', varname, FALSE); if (v != NULL) { copy_tv(&v->di_tv, rettv); done = TRUE; } } - - // restore previous notion of curbuf - curbuf = save_curbuf; } if (!done && argvars[2].v_type != VAR_UNKNOWN) @@ -3618,11 +3617,11 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED) } else { - buf_T *save_curbuf = curbuf; - bufvarname = alloc(STRLEN(varname) + 3); if (bufvarname != NULL) { + buf_T *save_curbuf = curbuf; + curbuf = buf; STRCPY(bufvarname, "b:"); STRCPY(bufvarname + 2, varname); diff --git a/src/version.c b/src/version.c index 59e601421..328203358 100644 --- 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 */ /**/ + 473, +/**/ 472, /**/ 471, |