patch 9.1.1808: Option insecure flags not copied when splitting window

Problem:  Option insecure flags not copied when splitting window.
Solution: Move window-local insecure flags to winopt_T and copy them
          properly (zeertzjq).

closes: #18434

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2025-09-29 19:30:07 +00:00
committed by Christian Brabandt
parent fec5586a45
commit b3740f4b00
15 changed files with 185 additions and 57 deletions

View File

@ -46,9 +46,9 @@ static char_u *option_expand(int opt_idx, char_u *val);
static void didset_options(void);
static void didset_options2(void);
#if defined(FEAT_EVAL) || defined(PROTO)
static long_u *insecure_flag(int opt_idx, int opt_flags);
static long_u *insecure_flag(win_T *wp, int opt_idx, int opt_flags);
#else
# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
# define insecure_flag(wp, opt_idx, opt_flags) (&options[opt_idx].flags)
#endif
static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags);
@ -829,11 +829,11 @@ set_option_default(
}
// The default value is not insecure.
flagsp = insecure_flag(opt_idx, opt_flags);
flagsp = insecure_flag(curwin, opt_idx, opt_flags);
*flagsp = *flagsp & ~P_INSECURE;
if (both)
{
flagsp = insecure_flag(opt_idx, OPT_LOCAL);
flagsp = insecure_flag(curwin, opt_idx, OPT_LOCAL);
*flagsp = *flagsp & ~P_INSECURE;
}
}
@ -2140,7 +2140,7 @@ do_set_option_string(
#endif
{
long_u *p = insecure_flag(opt_idx, opt_flags);
long_u *p = insecure_flag(curwin, opt_idx, opt_flags);
int secure_saved = secure;
// When an option is set in the sandbox, from a modeline or in secure
@ -2795,9 +2795,9 @@ did_set_option(
// When an option is set in the sandbox, from a modeline or in secure mode
// set the P_INSECURE flag. Otherwise, if a new value is stored reset the
// flag.
flagsp = insecure_flag(opt_idx, opt_flags);
flagsp = insecure_flag(curwin, opt_idx, opt_flags);
if (both)
flagsp_local = insecure_flag(opt_idx, OPT_LOCAL);
flagsp_local = insecure_flag(curwin, opt_idx, OPT_LOCAL);
if (!value_checked && (secure
#ifdef HAVE_SANDBOX
|| sandbox != 0
@ -3072,14 +3072,14 @@ set_term_option_alloced(char_u **p)
* Return -1 for an unknown option.
*/
int
was_set_insecurely(char_u *opt, int opt_flags)
was_set_insecurely(win_T *wp, char_u *opt, int opt_flags)
{
int idx = findoption(opt);
long_u *flagp;
if (idx >= 0)
{
flagp = insecure_flag(idx, opt_flags);
flagp = insecure_flag(wp, idx, opt_flags);
return (*flagp & P_INSECURE) != 0;
}
internal_error("was_set_insecurely()");
@ -3093,28 +3093,38 @@ was_set_insecurely(char_u *opt, int opt_flags)
* the option is used.
*/
static long_u *
insecure_flag(int opt_idx, int opt_flags)
insecure_flag(win_T *wp, int opt_idx, int opt_flags)
{
if (opt_flags & OPT_LOCAL)
switch ((int)options[opt_idx].indir)
{
case PV_WRAP: return &curwin->w_p_wrap_flags;
case PV_WRAP: return &wp->w_p_wrap_flags;
#ifdef FEAT_STL_OPT
case PV_STL: return &curwin->w_p_stl_flags;
case PV_STL: return &wp->w_p_stl_flags;
#endif
#ifdef FEAT_EVAL
# ifdef FEAT_FOLDING
case PV_FDE: return &curwin->w_p_fde_flags;
case PV_FDT: return &curwin->w_p_fdt_flags;
case PV_FDE: return &wp->w_p_fde_flags;
case PV_FDT: return &wp->w_p_fdt_flags;
# endif
# ifdef FEAT_BEVAL
case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
case PV_BEXPR: return &wp->w_buffer->b_p_bexpr_flags;
# endif
case PV_INDE: return &curbuf->b_p_inde_flags;
case PV_FEX: return &curbuf->b_p_fex_flags;
case PV_INDE: return &wp->w_buffer->b_p_inde_flags;
case PV_FEX: return &wp->w_buffer->b_p_fex_flags;
# ifdef FEAT_FIND_ID
case PV_INEX: return &curbuf->b_p_inex_flags;
case PV_INEX: return &wp->w_buffer->b_p_inex_flags;
# endif
#endif
}
else
// For global value of window-local options, use flags in w_allbuf_opt.
switch ((int)options[opt_idx].indir)
{
case PV_WRAP: return &wp->w_allbuf_opt.wo_wrap_flags;
#if defined(FEAT_EVAL) && defined(FEAT_FOLDING)
case PV_FDE: return &wp->w_allbuf_opt.wo_fde_flags;
case PV_FDT: return &wp->w_allbuf_opt.wo_fdt_flags;
#endif
}
@ -7141,6 +7151,15 @@ copy_winopt(winopt_T *from, winopt_T *to)
to->wo_lhi = from->wo_lhi;
#endif
to->wo_wrap_flags = from->wo_wrap_flags;
#ifdef FEAT_STL_OPT
to->wo_stl_flags = from->wo_stl_flags;
#endif
#ifdef FEAT_EVAL
to->wo_fde_flags = from->wo_fde_flags;
to->wo_fdt_flags = from->wo_fdt_flags;
#endif
#ifdef FEAT_EVAL
// Copy the script context so that we know where the value was last set.
mch_memmove(to->wo_script_ctx, from->wo_script_ctx,