changeset 36386:b238a0b68b89 draft v9.1.0813

patch 9.1.0813: no error handling with setglobal and number types Commit: https://github.com/vim/vim/commit/118072862b7c01cceb22f28fd85b1621cf03a2d1 Author: Milly <milly.ca@gmail.com> 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 <milly.ca@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Wed, 23 Oct 2024 22:00:02 +0200
parents 66ab44af9b01
children 9e6af2e63270
files src/option.c src/testdir/gen_opt_test.vim src/version.c
diffstat 3 files changed, 75 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/option.c
+++ b/src/option.c
@@ -3465,6 +3465,16 @@ did_set_conceallevel(optset_T *args UNUS
 	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 UNUSE
 	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 *arg
     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;
@@ -4153,6 +4204,18 @@ did_set_shiftwidth_tabstop(optset_T *arg
 	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
+    }
 
 #ifdef FEAT_FOLDING
     if (foldmethodIsIndent(curwin))
@@ -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)
--- 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.
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    813,
+/**/
     812,
 /**/
     811,