Skip to content

Commit d74af42

Browse files
committed
patch 8.1.1603: crash when using unknown highlighting in text property
Problem: Crash when using unknown highlighting in text property. Solution: Check for zero highlight ID.
1 parent 711d02c commit d74af42

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/screen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,7 +3171,7 @@ win_line(
31713171
int row; /* row in the window, excl w_winrow */
31723172
int screen_row; /* row on the screen, incl w_winrow */
31733173

3174-
char_u extra[18]; /* "%ld" and 'fdc' must fit in here */
3174+
char_u extra[20]; /* "%ld" and 'fdc' must fit in here */
31753175
int n_extra = 0; /* number of extra chars */
31763176
char_u *p_extra = NULL; /* string of extra chars, plus NUL */
31773177
char_u *p_extra_free = NULL; /* p_extra needs to be freed */
@@ -4440,7 +4440,7 @@ win_line(
44404440
proptype_T *pt = text_prop_type_by_id(
44414441
wp->w_buffer, text_props[tpi].tp_type);
44424442

4443-
if (pt != NULL)
4443+
if (pt != NULL && pt->pt_hl_id > 0)
44444444
{
44454445
int pt_attr = syn_id2attr(pt->pt_hl_id);
44464446

src/testdir/test_textprop.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,17 @@ func Test_textprop_empty_buffer()
792792
call prop_type_delete('comment')
793793
endfunc
794794

795+
" Adding a text property with invalid highlight should be ignored.
796+
func Test_textprop_invalid_highlight()
797+
call assert_fails("call prop_type_add('dni', {'highlight': 'DoesNotExist'})", 'E970:')
798+
new
799+
call setline(1, ['asdf','asdf'])
800+
call prop_add(1, 1, {'length': 4, 'type': 'dni'})
801+
redraw
802+
bwipe!
803+
call prop_type_delete('dni')
804+
endfunc
805+
795806
" Adding a text property to an empty buffer and then editing another
796807
func Test_textprop_empty_buffer_next()
797808
call prop_type_add("xxx", {})

src/version.c

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

778778
static int included_patches[] =
779779
{ /* Add new patch number below this line */
780+
/**/
781+
1603,
780782
/**/
781783
1602,
782784
/**/

0 commit comments

Comments
 (0)