Skip to content

Commit b06a6d5

Browse files
committed
patch 8.2.1537: memory acccess error when using setcellwidths()
Problem: Memory acccess error when using setcellwidths(). Solution: Use array and pointers correctly.
1 parent 4e4473c commit b06a6d5

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/errors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ EXTERN char e_list_item_nr_range_invalid[]
247247
EXTERN char e_list_item_nr_cell_width_invalid[]
248248
INIT(= N_("E1112: List item %d cell width invalid"));
249249
EXTERN char e_overlapping_ranges_for_nr[]
250-
INIT(= N_("E1113: Overlapping ranges for %lx"));
250+
INIT(= N_("E1113: Overlapping ranges for 0x%lx"));
251251
EXTERN char e_only_values_of_0x100_and_higher_supported[]
252252
INIT(= N_("E1114: Only values of 0x100 and higher supported"));
253253
#endif

src/mbyte.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5421,8 +5421,8 @@ cw_value(int c)
54215421
static int
54225422
tv_nr_compare(const void *a1, const void *a2)
54235423
{
5424-
listitem_T *li1 = (listitem_T *)a1;
5425-
listitem_T *li2 = (listitem_T *)a2;
5424+
listitem_T *li1 = *(listitem_T **)a1;
5425+
listitem_T *li2 = *(listitem_T **)a2;
54265426

54275427
return li1->li_tv.vval.v_number - li2->li_tv.vval.v_number;
54285428
}
@@ -5470,8 +5470,10 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
54705470
vim_free(ptrs);
54715471
return;
54725472
}
5473-
for (lili = li->li_tv.vval.v_list->lv_first, i = 0; lili != NULL;
5474-
lili = lili->li_next, ++i)
5473+
5474+
lili = li->li_tv.vval.v_list->lv_first;
5475+
ptrs[item] = lili;
5476+
for (i = 0; lili != NULL; lili = lili->li_next, ++i)
54755477
{
54765478
if (lili->li_tv.v_type != VAR_NUMBER)
54775479
break;
@@ -5505,7 +5507,7 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
55055507
vim_free(ptrs);
55065508
return;
55075509
}
5508-
ptrs[item++] = lili;
5510+
++item;
55095511
}
55105512

55115513
// Sort the list on the first number.
@@ -5520,9 +5522,9 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
55205522

55215523
// Store the items in the new table.
55225524
item = 0;
5523-
for (li = l->lv_first; li != NULL; li = li->li_next)
5525+
for (item = 0; item < l->lv_len; ++item)
55245526
{
5525-
listitem_T *lili = li->li_tv.vval.v_list->lv_first;
5527+
listitem_T *lili = ptrs[item];
55265528
varnumber_T n1;
55275529

55285530
n1 = lili->li_tv.vval.v_number;
@@ -5538,7 +5540,6 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
55385540
table[item].last = lili->li_tv.vval.v_number;
55395541
lili = lili->li_next;
55405542
table[item].width = lili->li_tv.vval.v_number;
5541-
++item;
55425543
}
55435544

55445545
vim_free(ptrs);

src/testdir/test_utf8.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ endfunc
148148
func Test_setcellwidths()
149149
call setcellwidths([
150150
\ [0x1330, 0x1330, 2],
151-
\ [0x1337, 0x1339, 2],
152151
\ [9999, 10000, 1],
152+
\ [0x1337, 0x1339, 2],
153153
\])
154154

155155
call assert_equal(2, strwidth("\u1330"))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1537,
757759
/**/
758760
1536,
759761
/**/

0 commit comments

Comments
 (0)