forked from aniani/vim
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>
This commit is contained in:
parent
d0809869d6
commit
118072862b
88
src/option.c
88
src/option.c
@ -3465,6 +3465,16 @@ did_set_conceallevel(optset_T *args UNUSED)
|
|||||||
errmsg = e_invalid_argument;
|
errmsg = e_invalid_argument;
|
||||||
curwin->w_p_cole = 3;
|
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;
|
return errmsg;
|
||||||
}
|
}
|
||||||
@ -3530,6 +3540,16 @@ did_set_foldcolumn(optset_T *args UNUSED)
|
|||||||
errmsg = e_invalid_argument;
|
errmsg = e_invalid_argument;
|
||||||
curwin->w_p_fdc = 12;
|
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;
|
return errmsg;
|
||||||
}
|
}
|
||||||
@ -3856,11 +3876,21 @@ did_set_numberwidth(optset_T *args UNUSED)
|
|||||||
errmsg = e_argument_must_be_positive;
|
errmsg = e_argument_must_be_positive;
|
||||||
curwin->w_p_nuw = 1;
|
curwin->w_p_nuw = 1;
|
||||||
}
|
}
|
||||||
if (curwin->w_p_nuw > 20)
|
else if (curwin->w_p_nuw > 20)
|
||||||
{
|
{
|
||||||
errmsg = e_invalid_argument;
|
errmsg = e_invalid_argument;
|
||||||
curwin->w_p_nuw = 20;
|
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
|
curwin->w_nrwidth_line_count = 0; // trigger a redraw
|
||||||
|
|
||||||
return errmsg;
|
return errmsg;
|
||||||
@ -4141,6 +4171,27 @@ did_set_shiftwidth_tabstop(optset_T *args)
|
|||||||
long *pp = (long *)args->os_varp;
|
long *pp = (long *)args->os_varp;
|
||||||
char *errmsg = NULL;
|
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)
|
if (curbuf->b_p_sw < 0)
|
||||||
{
|
{
|
||||||
errmsg = e_argument_must_be_positive;
|
errmsg = e_argument_must_be_positive;
|
||||||
@ -4151,6 +4202,18 @@ did_set_shiftwidth_tabstop(optset_T *args)
|
|||||||
: curbuf->b_p_ts;
|
: curbuf->b_p_ts;
|
||||||
#else
|
#else
|
||||||
curbuf->b_p_sw = curbuf->b_p_ts;
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4342,6 +4405,11 @@ did_set_textwidth(optset_T *args UNUSED)
|
|||||||
errmsg = e_argument_must_be_positive;
|
errmsg = e_argument_must_be_positive;
|
||||||
curbuf->b_p_tw = 0;
|
curbuf->b_p_tw = 0;
|
||||||
}
|
}
|
||||||
|
if (p_tw < 0)
|
||||||
|
{
|
||||||
|
errmsg = e_argument_must_be_positive;
|
||||||
|
p_tw = 0;
|
||||||
|
}
|
||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
{
|
{
|
||||||
win_T *wp;
|
win_T *wp;
|
||||||
@ -4810,16 +4878,6 @@ check_num_option_bounds(
|
|||||||
p_window = Rows - 1;
|
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)
|
if (p_tm < 0)
|
||||||
{
|
{
|
||||||
errmsg = e_argument_must_be_positive;
|
errmsg = e_argument_must_be_positive;
|
||||||
@ -4952,6 +5010,10 @@ set_num_option(
|
|||||||
need_mouse_correct = TRUE;
|
need_mouse_correct = TRUE;
|
||||||
#endif
|
#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
|
// Invoke the option specific callback function to validate and apply the
|
||||||
// new value.
|
// new value.
|
||||||
if (options[opt_idx].opt_did_set_cb != NULL)
|
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,
|
errmsg = check_num_option_bounds(pp, old_value, old_Rows, old_Columns,
|
||||||
errbuf, errbuflen, errmsg);
|
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;
|
options[opt_idx].flags |= P_WAS_SET;
|
||||||
|
|
||||||
#if defined(FEAT_EVAL)
|
#if defined(FEAT_EVAL)
|
||||||
|
@ -45,14 +45,6 @@ endwhile
|
|||||||
let skip_setglobal_reasons = #{
|
let skip_setglobal_reasons = #{
|
||||||
\ iminsert: 'The global value is always overwritten by the local value',
|
\ iminsert: 'The global value is always overwritten by the local value',
|
||||||
\ imsearch: '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.
|
" Script header.
|
||||||
|
@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
813,
|
||||||
/**/
|
/**/
|
||||||
812,
|
812,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user