mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid
Problem: setcellwidths() may make 'listchars' or 'fillchars' invalid. Solution: Check the value and give an error. (closes #9024)
This commit is contained in:
@@ -9648,6 +9648,9 @@ setcellwidths({list}) *setcellwidths()*
|
|||||||
range overlaps with another.
|
range overlaps with another.
|
||||||
Only characters with value 0x100 and higher can be used.
|
Only characters with value 0x100 and higher can be used.
|
||||||
|
|
||||||
|
If the new value causes 'fillchars' or 'listchars' to become
|
||||||
|
invalid it is rejected and an error is given.
|
||||||
|
|
||||||
To clear the overrides pass an empty list: >
|
To clear the overrides pass an empty list: >
|
||||||
setcellwidths([]);
|
setcellwidths([]);
|
||||||
< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
|
< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
|
||||||
|
@@ -160,6 +160,10 @@ EXTERN char e_list_value_does_not_have_enough_items[]
|
|||||||
INIT(= N_("E711: List value does not have enough items"));
|
INIT(= N_("E711: List value does not have enough items"));
|
||||||
EXTERN char e_cannot_slice_dictionary[]
|
EXTERN char e_cannot_slice_dictionary[]
|
||||||
INIT(= N_("E719: Cannot slice a Dictionary"));
|
INIT(= N_("E719: Cannot slice a Dictionary"));
|
||||||
|
EXTERN char e_conflicts_with_value_of_listchars[]
|
||||||
|
INIT(= N_("E834: Conflicts with value of 'listchars'"));
|
||||||
|
EXTERN char e_conflicts_with_value_of_fillchars[]
|
||||||
|
INIT(= N_("E835: Conflicts with value of 'fillchars'"));
|
||||||
EXTERN char e_assert_fails_second_arg[]
|
EXTERN char e_assert_fails_second_arg[]
|
||||||
INIT(= N_("E856: \"assert_fails()\" second argument must be a string or a list with one or two strings"));
|
INIT(= N_("E856: \"assert_fails()\" second argument must be a string or a list with one or two strings"));
|
||||||
EXTERN char e_using_invalid_value_as_string_str[]
|
EXTERN char e_using_invalid_value_as_string_str[]
|
||||||
|
36
src/mbyte.c
36
src/mbyte.c
@@ -5510,6 +5510,8 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
int i;
|
int i;
|
||||||
listitem_T **ptrs;
|
listitem_T **ptrs;
|
||||||
cw_interval_T *table;
|
cw_interval_T *table;
|
||||||
|
cw_interval_T *cw_table_save;
|
||||||
|
size_t cw_table_size_save;
|
||||||
|
|
||||||
if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL)
|
if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL)
|
||||||
return;
|
return;
|
||||||
@@ -5620,9 +5622,41 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
vim_free(ptrs);
|
vim_free(ptrs);
|
||||||
vim_free(cw_table);
|
|
||||||
|
cw_table_save = cw_table;
|
||||||
|
cw_table_size_save = cw_table_size;
|
||||||
cw_table = table;
|
cw_table = table;
|
||||||
cw_table_size = l->lv_len;
|
cw_table_size = l->lv_len;
|
||||||
|
|
||||||
|
// Check that the new value does not conflict with 'fillchars' or
|
||||||
|
// 'listchars'.
|
||||||
|
if (set_chars_option(curwin, &p_fcs) != NULL)
|
||||||
|
{
|
||||||
|
emsg(_(e_conflicts_with_value_of_fillchars));
|
||||||
|
cw_table = cw_table_save;
|
||||||
|
cw_table_size = cw_table_size_save;
|
||||||
|
vim_free(table);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tabpage_T *tp;
|
||||||
|
win_T *wp;
|
||||||
|
|
||||||
|
FOR_ALL_TAB_WINDOWS(tp, wp)
|
||||||
|
{
|
||||||
|
if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
|
||||||
|
{
|
||||||
|
emsg((e_conflicts_with_value_of_listchars));
|
||||||
|
cw_table = cw_table_save;
|
||||||
|
cw_table_size = cw_table_size_save;
|
||||||
|
vim_free(table);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vim_free(cw_table_save);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -871,7 +871,7 @@ did_set_string_option(
|
|||||||
if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
|
if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
|
||||||
errmsg = e_invarg;
|
errmsg = e_invarg;
|
||||||
else if (set_chars_option(curwin, &p_fcs) != NULL)
|
else if (set_chars_option(curwin, &p_fcs) != NULL)
|
||||||
errmsg = _("E835: Conflicts with value of 'fillchars'");
|
errmsg = _(e_conflicts_with_value_of_fillchars);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tabpage_T *tp;
|
tabpage_T *tp;
|
||||||
@@ -881,7 +881,7 @@ did_set_string_option(
|
|||||||
{
|
{
|
||||||
if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
|
if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
|
||||||
{
|
{
|
||||||
errmsg = _("E834: Conflicts with value of 'listchars'");
|
errmsg = _(e_conflicts_with_value_of_listchars);
|
||||||
goto ambw_end;
|
goto ambw_end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -185,6 +185,16 @@ func Test_setcellwidths()
|
|||||||
call assert_fails('call setcellwidths([[0x111, 0x122, 1], [0x122, 0x123, 2]])', 'E1113:')
|
call assert_fails('call setcellwidths([[0x111, 0x122, 1], [0x122, 0x123, 2]])', 'E1113:')
|
||||||
|
|
||||||
call assert_fails('call setcellwidths([[0x33, 0x44, 2]])', 'E1114:')
|
call assert_fails('call setcellwidths([[0x33, 0x44, 2]])', 'E1114:')
|
||||||
|
|
||||||
|
set listchars=tab:--\\u2192
|
||||||
|
call assert_fails('call setcellwidths([[0x2192, 0x2192, 2]])', 'E834:')
|
||||||
|
|
||||||
|
set fillchars=stl:\\u2501
|
||||||
|
call assert_fails('call setcellwidths([[0x2501, 0x2501, 2]])', 'E835:')
|
||||||
|
|
||||||
|
set listchars&
|
||||||
|
set fillchars&
|
||||||
|
call setcellwidths([])
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_print_overlong()
|
func Test_print_overlong()
|
||||||
|
@@ -757,6 +757,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 */
|
||||||
|
/**/
|
||||||
|
3545,
|
||||||
/**/
|
/**/
|
||||||
3544,
|
3544,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user