Skip to content

Commit 1180728

Browse files
Millychrisbra
authored andcommitted
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>
1 parent d080986 commit 1180728

3 files changed

Lines changed: 75 additions & 23 deletions

File tree

src/option.c

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,16 @@ did_set_conceallevel(optset_T *args UNUSED)
34653465
errmsg = e_invalid_argument;
34663466
curwin->w_p_cole = 3;
34673467
}
3468+
if (curwin->w_allbuf_opt.wo_cole < 0)
3469+
{
3470+
errmsg = e_argument_must_be_positive;
3471+
curwin->w_allbuf_opt.wo_cole = 0;
3472+
}
3473+
else if (curwin->w_allbuf_opt.wo_cole > 3)
3474+
{
3475+
errmsg = e_invalid_argument;
3476+
curwin->w_allbuf_opt.wo_cole = 3;
3477+
}
34683478

34693479
return errmsg;
34703480
}
@@ -3530,6 +3540,16 @@ did_set_foldcolumn(optset_T *args UNUSED)
35303540
errmsg = e_invalid_argument;
35313541
curwin->w_p_fdc = 12;
35323542
}
3543+
if (curwin->w_allbuf_opt.wo_fdc < 0)
3544+
{
3545+
errmsg = e_argument_must_be_positive;
3546+
curwin->w_allbuf_opt.wo_fdc = 0;
3547+
}
3548+
else if (curwin->w_allbuf_opt.wo_fdc > 12)
3549+
{
3550+
errmsg = e_invalid_argument;
3551+
curwin->w_allbuf_opt.wo_fdc = 12;
3552+
}
35333553

35343554
return errmsg;
35353555
}
@@ -3856,11 +3876,21 @@ did_set_numberwidth(optset_T *args UNUSED)
38563876
errmsg = e_argument_must_be_positive;
38573877
curwin->w_p_nuw = 1;
38583878
}
3859-
if (curwin->w_p_nuw > 20)
3879+
else if (curwin->w_p_nuw > 20)
38603880
{
38613881
errmsg = e_invalid_argument;
38623882
curwin->w_p_nuw = 20;
38633883
}
3884+
if (curwin->w_allbuf_opt.wo_nuw < 1)
3885+
{
3886+
errmsg = e_argument_must_be_positive;
3887+
curwin->w_allbuf_opt.wo_nuw = 1;
3888+
}
3889+
else if (curwin->w_allbuf_opt.wo_nuw > 20)
3890+
{
3891+
errmsg = e_invalid_argument;
3892+
curwin->w_allbuf_opt.wo_nuw = 20;
3893+
}
38643894
curwin->w_nrwidth_line_count = 0; // trigger a redraw
38653895

38663896
return errmsg;
@@ -4141,6 +4171,27 @@ did_set_shiftwidth_tabstop(optset_T *args)
41414171
long *pp = (long *)args->os_varp;
41424172
char *errmsg = NULL;
41434173

4174+
if (curbuf->b_p_ts <= 0)
4175+
{
4176+
errmsg = e_argument_must_be_positive;
4177+
curbuf->b_p_ts = 8;
4178+
}
4179+
else if (curbuf->b_p_ts > TABSTOP_MAX)
4180+
{
4181+
errmsg = e_invalid_argument;
4182+
curbuf->b_p_ts = 8;
4183+
}
4184+
if (p_ts <= 0)
4185+
{
4186+
errmsg = e_argument_must_be_positive;
4187+
p_ts = 8;
4188+
}
4189+
else if (p_ts > TABSTOP_MAX)
4190+
{
4191+
errmsg = e_invalid_argument;
4192+
p_ts = 8;
4193+
}
4194+
41444195
if (curbuf->b_p_sw < 0)
41454196
{
41464197
errmsg = e_argument_must_be_positive;
@@ -4151,6 +4202,18 @@ did_set_shiftwidth_tabstop(optset_T *args)
41514202
: curbuf->b_p_ts;
41524203
#else
41534204
curbuf->b_p_sw = curbuf->b_p_ts;
4205+
#endif
4206+
}
4207+
if (p_sw < 0)
4208+
{
4209+
errmsg = e_argument_must_be_positive;
4210+
#ifdef FEAT_VARTABS
4211+
// Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
4212+
p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
4213+
? tabstop_first(curbuf->b_p_vts_array)
4214+
: curbuf->b_p_ts;
4215+
#else
4216+
p_sw = curbuf->b_p_ts;
41544217
#endif
41554218
}
41564219

@@ -4342,6 +4405,11 @@ did_set_textwidth(optset_T *args UNUSED)
43424405
errmsg = e_argument_must_be_positive;
43434406
curbuf->b_p_tw = 0;
43444407
}
4408+
if (p_tw < 0)
4409+
{
4410+
errmsg = e_argument_must_be_positive;
4411+
p_tw = 0;
4412+
}
43454413
#ifdef FEAT_SYN_HL
43464414
{
43474415
win_T *wp;
@@ -4810,16 +4878,6 @@ check_num_option_bounds(
48104878
p_window = Rows - 1;
48114879
}
48124880

4813-
if (curbuf->b_p_ts <= 0)
4814-
{
4815-
errmsg = e_argument_must_be_positive;
4816-
curbuf->b_p_ts = 8;
4817-
}
4818-
else if (curbuf->b_p_ts > TABSTOP_MAX)
4819-
{
4820-
errmsg = e_invalid_argument;
4821-
curbuf->b_p_ts = 8;
4822-
}
48234881
if (p_tm < 0)
48244882
{
48254883
errmsg = e_argument_must_be_positive;
@@ -4952,6 +5010,10 @@ set_num_option(
49525010
need_mouse_correct = TRUE;
49535011
#endif
49545012

5013+
// May set global value for local option.
5014+
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
5015+
*(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
5016+
49555017
// Invoke the option specific callback function to validate and apply the
49565018
// new value.
49575019
if (options[opt_idx].opt_did_set_cb != NULL)
@@ -4971,10 +5033,6 @@ set_num_option(
49715033
errmsg = check_num_option_bounds(pp, old_value, old_Rows, old_Columns,
49725034
errbuf, errbuflen, errmsg);
49735035

4974-
// May set global value for local option.
4975-
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4976-
*(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
4977-
49785036
options[opt_idx].flags |= P_WAS_SET;
49795037

49805038
#if defined(FEAT_EVAL)

src/testdir/gen_opt_test.vim

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ endwhile
4545
let skip_setglobal_reasons = #{
4646
\ iminsert: 'The global value is always overwritten by the local value',
4747
\ imsearch: 'The global value is always overwritten by the local value',
48-
\ conceallevel: 'TODO: fix missing error handling for setglobal',
49-
\ foldcolumn: 'TODO: fix missing error handling for setglobal',
50-
\ numberwidth: 'TODO: fix missing error handling for setglobal',
51-
\ scrolloff: 'TODO: fix missing error handling for setglobal',
52-
\ shiftwidth: 'TODO: fix missing error handling for setglobal',
53-
\ sidescrolloff: 'TODO: fix missing error handling for setglobal',
54-
\ tabstop: 'TODO: fix missing error handling for setglobal',
55-
\ textwidth: 'TODO: fix missing error handling for setglobal',
5648
\}
5749

5850
" Script header.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
813,
707709
/**/
708710
812,
709711
/**/

0 commit comments

Comments
 (0)