patch 9.1.0813: no error handling with setglobal and number types
Commit:
https://github.com/vim/vim/commit/118072862b7c01cceb22f28fd85b1621cf03a2d1
Author: Milly <[email protected]>
Date: Wed Oct 23 21:42:41 2024 +0200
patch 9.1.0813: no error handling with setglobal and number types
Problem: no error handling with setglobal and number types
Solution: validate values when using :setglobal with number option types
(Milly)
closes: #15928
Signed-off-by: Milly <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/option.c b/src/option.c
index e82a79b6b..f408fb9df 100644
--- a/src/option.c
+++ b/src/option.c
@@ -3465,6 +3465,16 @@ did_set_conceallevel(optset_T *args UNUSED)
errmsg = e_invalid_argument;
curwin->w_p_cole = 3;
}
+ if (curwin->w_allbuf_opt.wo_cole < 0)
+ {
+ errmsg = e_argument_must_be_positive;
+ curwin->w_allbuf_opt.wo_cole = 0;
+ }
+ else if (curwin->w_allbuf_opt.wo_cole > 3)
+ {
+ errmsg = e_invalid_argument;
+ curwin->w_allbuf_opt.wo_cole = 3;
+ }
return errmsg;
}
@@ -3530,6 +3540,16 @@ did_set_foldcolumn(optset_T *args UNUSED)
errmsg = e_invalid_argument;
curwin->w_p_fdc = 12;
}
+ if (curwin->w_allbuf_opt.wo_fdc < 0)
+ {
+ errmsg = e_argument_must_be_positive;
+ curwin->w_allbuf_opt.wo_fdc = 0;
+ }
+ else if (curwin->w_allbuf_opt.wo_fdc > 12)
+ {
+ errmsg = e_invalid_argument;
+ curwin->w_allbuf_opt.wo_fdc = 12;
+ }
return errmsg;
}
@@ -3856,11 +3876,21 @@ did_set_numberwidth(optset_T *args UNUSED)
errmsg = e_argument_must_be_positive;
curwin->w_p_nuw = 1;
}
- if (curwin->w_p_nuw > 20)
+ else if (curwin->w_p_nuw > 20)
{
errmsg = e_invalid_argument;
curwin->w_p_nuw = 20;
}
+ if (curwin->w_allbuf_opt.wo_nuw < 1)
+ {
+ errmsg = e_argument_must_be_positive;
+ curwin->w_allbuf_opt.wo_nuw = 1;
+ }
+ else if (curwin->w_allbuf_opt.wo_nuw > 20)
+ {
+ errmsg = e_invalid_argument;
+ curwin->w_allbuf_opt.wo_nuw = 20;
+ }
curwin->w_nrwidth_line_count = 0; // trigger a redraw
return errmsg;
@@ -4141,6 +4171,27 @@ did_set_shiftwidth_tabstop(optset_T *args)
long *pp = (long *)args->os_varp;
char *errmsg = NULL;
+ if (curbuf->b_p_ts <= 0)
+ {
+ errmsg = e_argument_must_be_positive;
+ curbuf->b_p_ts = 8;
+ }
+ else if (curbuf->b_p_ts > TABSTOP_MAX)
+ {
+ errmsg = e_invalid_argument;
+ curbuf->b_p_ts = 8;
+ }
+ if (p_ts <= 0)
+ {
+ errmsg = e_argument_must_be_positive;
+ p_ts = 8;
+ }
+ else if (p_ts > TABSTOP_MAX)
+ {
+ errmsg = e_invalid_argument;
+ p_ts = 8;
+ }
+
if (curbuf->b_p_sw < 0)
{
errmsg = e_argument_must_be_positive;
@@ -4151,6 +4202,18 @@ did_set_shiftwidth_tabstop(optset_T *args)
: curbuf->b_p_ts;
#else
curbuf->b_p_sw = curbuf->b_p_ts;
+#endif
+ }
+ if (p_sw < 0)
+ {
+ errmsg = e_argument_must_be_positive;
+#ifdef FEAT_VARTABS
+ // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
+ p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
+ ? tabstop_first(curbuf->b_p_vts_array)
+ : curbuf->b_p_ts;
+#else
+ p_sw = curbuf->b_p_ts;
#endif
}
@@ -4342,6 +4405,11 @@ did_set_textwidth(optset_T *args UNUSED)
errmsg = e_argument_must_be_positive;
curbuf->b_p_tw = 0;
}
+ if (p_tw < 0)
+ {
+ errmsg = e_argument_must_be_positive;
+ p_tw = 0;
+ }
#ifdef FEAT_SYN_HL
{
win_T *wp;
@@ -4810,16 +4878,6 @@ check_num_option_bounds(
p_window = Rows - 1;
}
- if (curbuf->b_p_ts <= 0)
- {
- errmsg = e_argument_must_be_positive;
- curbuf->b_p_ts = 8;
- }
- else if (curbuf->b_p_ts > TABSTOP_MAX)
- {
- errmsg = e_invalid_argument;
- curbuf->b_p_ts = 8;
- }
if (p_tm < 0)
{
errmsg = e_argument_must_be_positive;
@@ -4952,6 +5010,10 @@ set_num_option(
need_mouse_correct = TRUE;
#endif
+ // May set global value for local option.
+ if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
+ *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
+
// Invoke the option specific callback function to validate and apply the
// new value.
if (options[opt_idx].opt_did_set_cb != NULL)
@@ -4971,10 +5033,6 @@ set_num_option(
errmsg = check_num_option_bounds(pp, old_value, old_Rows, old_Columns,
errbuf, errbuflen, errmsg);
- // May set global value for local option.
- if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
- *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
-
options[opt_idx].flags |= P_WAS_SET;
#if defined(FEAT_EVAL)
diff --git a/src/testdir/gen_opt_test.vim b/src/testdir/gen_opt_test.vim
index 34fffeff6..afea28b7e 100644
--- a/src/testdir/gen_opt_test.vim
+++ b/src/testdir/gen_opt_test.vim
@@ -45,14 +45,6 @@ endwhile
let skip_setglobal_reasons = #{
\ iminsert: 'The global value is always overwritten by the local value',
\ imsearch: 'The global value is always overwritten by the local value',
- \ conceallevel: 'TODO: fix missing error handling for setglobal',
- \ foldcolumn: 'TODO: fix missing error handling for setglobal',
- \ numberwidth: 'TODO: fix missing error handling for setglobal',
- \ scrolloff: 'TODO: fix missing error handling for setglobal',
- \ shiftwidth: 'TODO: fix missing error handling for setglobal',
- \ sidescrolloff: 'TODO: fix missing error handling for setglobal',
- \ tabstop: 'TODO: fix missing error handling for setglobal',
- \ textwidth: 'TODO: fix missing error handling for setglobal',
\}
" Script header.
diff --git a/src/version.c b/src/version.c
index 1f66cef8a..1b3c92192 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 813,
/**/
812,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1t3hWU-002cKG-Q3%40256bit.org.