diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-11-22 20:10:18 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-11-22 20:10:18 +0000 |
commit | 3b3755fe19e9ded2a1c45f14b2c6fa065bcaf2c6 (patch) | |
tree | 92ed5f9e604bc7f42fcf6ddf0fd2499f46accb85 /src/evalvars.c | |
parent | 7a53f29c031f54ab67a803e5e3f8cb44e4edc4bc (diff) |
patch 8.2.3650: Vim9: for loop variable can be a list memberv8.2.3650
Problem: Vim9: for loop variable can be a list member.
Solution: Check for valid variable name. (closes #9179)
Diffstat (limited to 'src/evalvars.c')
-rw-r--r-- | src/evalvars.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index afbab79ff4..b56073453b 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -3431,7 +3431,7 @@ set_var_const( // Make sure the variable name is valid. In Vim9 script an autoload // variable must be prefixed with "g:". - if (!valid_varname(varname, !vim9script + if (!valid_varname(varname, -1, !vim9script || STRNCMP(name, "g:", 2) == 0)) goto failed; @@ -3631,14 +3631,15 @@ value_check_lock(int lock, char_u *name, int use_gettext) /* * Check if a variable name is valid. When "autoload" is true "#" is allowed. + * If "len" is -1 use all of "varname", otherwise up to "varname[len]". * Return FALSE and give an error if not. */ int -valid_varname(char_u *varname, int autoload) +valid_varname(char_u *varname, int len, int autoload) { char_u *p; - for (p = varname; *p != NUL; ++p) + for (p = varname; len < 0 ? *p != NUL : p < varname + len; ++p) if (!eval_isnamec1(*p) && (p == varname || !VIM_ISDIGIT(*p)) && !(autoload && *p == AUTOLOAD_CHAR)) { |