api: handle null string in buffer_add_highlight

This commit is contained in:
Björn Linse 2016-08-16 21:55:37 +02:00
parent c9b29d3884
commit 57ac9b0934
2 changed files with 7 additions and 3 deletions

View File

@ -691,7 +691,7 @@ Integer buffer_add_highlight(Buffer buffer,
col_end = MAXCOL;
}
int hlg_id = syn_name2id((char_u*)hl_group.data);
int hlg_id = syn_name2id((char_u *)(hl_group.data ? hl_group.data : ""));
src_id = bufhl_add_hl(buf, (int)src_id, hlg_id, (linenr_T)line+1,
(colnr_T)col_start+1, (colnr_T)col_end);
return src_id;

View File

@ -111,12 +111,16 @@ describe('Buffer highlighting', function()
add_hl(id1, "ImportantWord", 2, 0, 9)
add_hl(id1, "ImportantWord", 3, 5, 14)
id2 = add_hl(0, "Special", 0, 2, 8)
-- add_highlight can be called like this to get a new source
-- without adding any highlight
id2 = add_hl(0, "", 0, 0, 0)
neq(id1, id2)
add_hl(id2, "Special", 0, 2, 8)
add_hl(id2, "Identifier", 1, 3, 8)
add_hl(id2, "Special", 1, 14, 20)
add_hl(id2, "Underlined", 2, 6, 12)
add_hl(id2, "Underlined", 3, 0, 9)
neq(id1, id2)
screen:expect([[
a {5:longer} example |