summaryrefslogtreecommitdiff
path: root/src/evalvars.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-08-19 21:20:49 +0200
committerBram Moolenaar <Bram@vim.org>2020-08-19 21:20:49 +0200
commit191929b182ba38abe6bc431fb9d8d9507f408903 (patch)
tree6b3f1b39993d579f1cefa0f29a173d883860f1ac /src/evalvars.c
parent9dc1917f42b23277e143fc58bbe27482b0b76bad (diff)
downloadvim-git-191929b182ba38abe6bc431fb9d8d9507f408903.tar.gz
patch 8.2.1489: Vim9: error when setting an option with setbufvar()v8.2.1489
Problem: Vim9: error when setting an option with setbufvar(). Solution: Do not get a number from a string value. (closes #6740)
Diffstat (limited to 'src/evalvars.c')
-rw-r--r--src/evalvars.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index f59dde9c6..bff6086e5 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3293,6 +3293,24 @@ getwinvar(
}
/*
+ * Set option "varname" to the value of "varp" for the current buffer/window.
+ */
+ static void
+set_option_from_tv(char_u *varname, typval_T *varp)
+{
+ long numval = 0;
+ char_u *strval;
+ char_u nbuf[NUMBUFLEN];
+ int error = FALSE;
+
+ if (!in_vim9script() || varp->v_type != VAR_STRING)
+ numval = (long)tv_get_number_chk(varp, &error);
+ strval = tv_get_string_buf_chk(varp, nbuf);
+ if (!error && strval != NULL)
+ set_option_value(varname, numval, strval, OPT_LOCAL);
+}
+
+/*
* "setwinvar()" and "settabwinvar()" functions
*/
static void
@@ -3304,7 +3322,6 @@ setwinvar(typval_T *argvars, int off)
int need_switch_win;
char_u *varname, *winvarname;
typval_T *varp;
- char_u nbuf[NUMBUFLEN];
tabpage_T *tp = NULL;
if (check_secure())
@@ -3325,17 +3342,7 @@ setwinvar(typval_T *argvars, int off)
|| switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK)
{
if (*varname == '&')
- {
- long numval;
- char_u *strval;
- int error = FALSE;
-
- ++varname;
- numval = (long)tv_get_number_chk(varp, &error);
- strval = tv_get_string_buf_chk(varp, nbuf);
- if (!error && strval != NULL)
- set_option_value(varname, numval, strval, OPT_LOCAL);
- }
+ set_option_from_tv(varname + 1, varp);
else
{
winvarname = alloc(STRLEN(varname) + 3);
@@ -3759,7 +3766,6 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
buf_T *buf;
char_u *varname, *bufvarname;
typval_T *varp;
- char_u nbuf[NUMBUFLEN];
if (check_secure())
return;
@@ -3772,19 +3778,12 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
{
if (*varname == '&')
{
- long numval;
- char_u *strval;
- int error = FALSE;
aco_save_T aco;
// set curbuf to be our buf, temporarily
aucmd_prepbuf(&aco, buf);
- ++varname;
- numval = (long)tv_get_number_chk(varp, &error);
- strval = tv_get_string_buf_chk(varp, nbuf);
- if (!error && strval != NULL)
- set_option_value(varname, numval, strval, OPT_LOCAL);
+ set_option_from_tv(varname + 1, varp);
// reset notion of buffer
aucmd_restbuf(&aco);