Skip to content

Commit 66f65a4

Browse files
zeertzjqchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 82f6134 commit 66f65a4

3 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/mbyte.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5630,7 +5630,8 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
56305630
int item;
56315631
int i;
56325632
listitem_T **ptrs;
5633-
cw_interval_T *table;
5633+
cw_interval_T *table = NULL;
5634+
size_t table_size;
56345635
cw_interval_T *cw_table_save;
56355636
size_t cw_table_size_save;
56365637
char *error = NULL;
@@ -5639,15 +5640,12 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
56395640
return;
56405641

56415642
l = argvars[0].vval.v_list;
5642-
if (l->lv_len == 0)
5643-
{
5643+
table_size = (size_t)l->lv_len;
5644+
if (table_size == 0)
56445645
// Clearing the table.
5645-
VIM_CLEAR(cw_table);
5646-
cw_table_size = 0;
5647-
goto done;
5648-
}
5646+
goto update;
56495647

5650-
ptrs = ALLOC_MULT(listitem_T *, l->lv_len);
5648+
ptrs = ALLOC_MULT(listitem_T *, table_size);
56515649
if (ptrs == NULL)
56525650
return;
56535651

@@ -5706,17 +5704,17 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
57065704
}
57075705

57085706
// Sort the list on the first number.
5709-
qsort((void *)ptrs, (size_t)l->lv_len, sizeof(listitem_T *), tv_nr_compare);
5707+
qsort((void *)ptrs, table_size, sizeof(listitem_T *), tv_nr_compare);
57105708

5711-
table = ALLOC_MULT(cw_interval_T, l->lv_len);
5709+
table = ALLOC_MULT(cw_interval_T, table_size);
57125710
if (table == NULL)
57135711
{
57145712
vim_free(ptrs);
57155713
return;
57165714
}
57175715

57185716
// Store the items in the new table.
5719-
for (item = 0; item < l->lv_len; ++item)
5717+
for (item = 0; (size_t)item < table_size; ++item)
57205718
{
57215719
listitem_T *lili = ptrs[item];
57225720
varnumber_T n1;
@@ -5738,10 +5736,11 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
57385736

57395737
vim_free(ptrs);
57405738

5739+
update:
57415740
cw_table_save = cw_table;
57425741
cw_table_size_save = cw_table_size;
57435742
cw_table = table;
5744-
cw_table_size = l->lv_len;
5743+
cw_table_size = table_size;
57455744

57465745
// Check that the new value does not conflict with 'listchars' or
57475746
// 'fillchars'.
@@ -5756,7 +5755,6 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
57565755
}
57575756

57585757
vim_free(cw_table_save);
5759-
done:
57605758
changed_window_setting_all();
57615759
redraw_all_later(UPD_CLEAR);
57625760
}

src/testdir/test_utf8.vim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,21 @@ func Test_setcellwidths()
255255

256256
call assert_fails('call setcellwidths([[0x33, 0x44, 2]])', 'E1114:')
257257

258-
set listchars=tab:--\\u2192
258+
set listchars=tab:--\\u2192 fillchars=stl:\\u2501
259259
call assert_fails('call setcellwidths([[0x2192, 0x2192, 2]])', 'E834:')
260-
261-
set fillchars=stl:\\u2501
262260
call assert_fails('call setcellwidths([[0x2501, 0x2501, 2]])', 'E835:')
263261

262+
call setcellwidths([[0x201c, 0x201d, 1]])
263+
set listchars& fillchars& ambiwidth=double
264+
265+
set listchars=nbsp:\\u201c fillchars=vert:\\u201d
266+
call assert_fails('call setcellwidths([])', 'E834:')
264267
set listchars&
268+
call assert_fails('call setcellwidths([])', 'E835:')
265269
set fillchars&
270+
266271
call setcellwidths([])
272+
set ambiwidth&
267273
bwipe!
268274
endfunc
269275

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+
719,
707709
/**/
708710
718,
709711
/**/

0 commit comments

Comments
 (0)