forked from aniani/vim
patch 9.1.0719: Resetting cell widths can make 'listchars' or 'fillchars' invalid
Problem: Resetting cell widths can make 'listchars' or 'fillchars' invalid. Solution: Check for conflicts when resetting cell widths (zeertzjq). closes: #15629 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
82f6134b1b
commit
66f65a46c5
24
src/mbyte.c
24
src/mbyte.c
@@ -5630,7 +5630,8 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
int item;
|
int item;
|
||||||
int i;
|
int i;
|
||||||
listitem_T **ptrs;
|
listitem_T **ptrs;
|
||||||
cw_interval_T *table;
|
cw_interval_T *table = NULL;
|
||||||
|
size_t table_size;
|
||||||
cw_interval_T *cw_table_save;
|
cw_interval_T *cw_table_save;
|
||||||
size_t cw_table_size_save;
|
size_t cw_table_size_save;
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
@@ -5639,15 +5640,12 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
l = argvars[0].vval.v_list;
|
l = argvars[0].vval.v_list;
|
||||||
if (l->lv_len == 0)
|
table_size = (size_t)l->lv_len;
|
||||||
{
|
if (table_size == 0)
|
||||||
// Clearing the table.
|
// Clearing the table.
|
||||||
VIM_CLEAR(cw_table);
|
goto update;
|
||||||
cw_table_size = 0;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptrs = ALLOC_MULT(listitem_T *, l->lv_len);
|
ptrs = ALLOC_MULT(listitem_T *, table_size);
|
||||||
if (ptrs == NULL)
|
if (ptrs == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -5706,9 +5704,9 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort the list on the first number.
|
// Sort the list on the first number.
|
||||||
qsort((void *)ptrs, (size_t)l->lv_len, sizeof(listitem_T *), tv_nr_compare);
|
qsort((void *)ptrs, table_size, sizeof(listitem_T *), tv_nr_compare);
|
||||||
|
|
||||||
table = ALLOC_MULT(cw_interval_T, l->lv_len);
|
table = ALLOC_MULT(cw_interval_T, table_size);
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
{
|
{
|
||||||
vim_free(ptrs);
|
vim_free(ptrs);
|
||||||
@@ -5716,7 +5714,7 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store the items in the new table.
|
// Store the items in the new table.
|
||||||
for (item = 0; item < l->lv_len; ++item)
|
for (item = 0; (size_t)item < table_size; ++item)
|
||||||
{
|
{
|
||||||
listitem_T *lili = ptrs[item];
|
listitem_T *lili = ptrs[item];
|
||||||
varnumber_T n1;
|
varnumber_T n1;
|
||||||
@@ -5738,10 +5736,11 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
|
|
||||||
vim_free(ptrs);
|
vim_free(ptrs);
|
||||||
|
|
||||||
|
update:
|
||||||
cw_table_save = cw_table;
|
cw_table_save = cw_table;
|
||||||
cw_table_size_save = cw_table_size;
|
cw_table_size_save = cw_table_size;
|
||||||
cw_table = table;
|
cw_table = table;
|
||||||
cw_table_size = l->lv_len;
|
cw_table_size = table_size;
|
||||||
|
|
||||||
// Check that the new value does not conflict with 'listchars' or
|
// Check that the new value does not conflict with 'listchars' or
|
||||||
// 'fillchars'.
|
// 'fillchars'.
|
||||||
@@ -5756,7 +5755,6 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
vim_free(cw_table_save);
|
vim_free(cw_table_save);
|
||||||
done:
|
|
||||||
changed_window_setting_all();
|
changed_window_setting_all();
|
||||||
redraw_all_later(UPD_CLEAR);
|
redraw_all_later(UPD_CLEAR);
|
||||||
}
|
}
|
||||||
|
@@ -255,15 +255,21 @@ func Test_setcellwidths()
|
|||||||
|
|
||||||
call assert_fails('call setcellwidths([[0x33, 0x44, 2]])', 'E1114:')
|
call assert_fails('call setcellwidths([[0x33, 0x44, 2]])', 'E1114:')
|
||||||
|
|
||||||
set listchars=tab:--\\u2192
|
set listchars=tab:--\\u2192 fillchars=stl:\\u2501
|
||||||
call assert_fails('call setcellwidths([[0x2192, 0x2192, 2]])', 'E834:')
|
call assert_fails('call setcellwidths([[0x2192, 0x2192, 2]])', 'E834:')
|
||||||
|
|
||||||
set fillchars=stl:\\u2501
|
|
||||||
call assert_fails('call setcellwidths([[0x2501, 0x2501, 2]])', 'E835:')
|
call assert_fails('call setcellwidths([[0x2501, 0x2501, 2]])', 'E835:')
|
||||||
|
|
||||||
|
call setcellwidths([[0x201c, 0x201d, 1]])
|
||||||
|
set listchars& fillchars& ambiwidth=double
|
||||||
|
|
||||||
|
set listchars=nbsp:\\u201c fillchars=vert:\\u201d
|
||||||
|
call assert_fails('call setcellwidths([])', 'E834:')
|
||||||
set listchars&
|
set listchars&
|
||||||
|
call assert_fails('call setcellwidths([])', 'E835:')
|
||||||
set fillchars&
|
set fillchars&
|
||||||
|
|
||||||
call setcellwidths([])
|
call setcellwidths([])
|
||||||
|
set ambiwidth&
|
||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
719,
|
||||||
/**/
|
/**/
|
||||||
718,
|
718,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user