Detect infinit recursion in reference highlighting

Reference highlighters allow for potential mutual recursion between
highlighters. This is usually fine, but if the recursion happens on
the same buffer range, it means we will recurse infinitely.

Fixes #1920
This commit is contained in:
Maxime Coste 2018-03-11 11:40:26 +11:00
parent 4584ecac77
commit e66073bc94
5 changed files with 19 additions and 0 deletions

View File

@ -1581,6 +1581,14 @@ struct ReferenceHighlighter : Highlighter
private:
void do_highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range) override
{
static Vector<std::pair<StringView, BufferRange>> running_refs;
const std::pair<StringView, BufferRange> desc{m_name, range};
if (contains(running_refs, desc))
return write_to_debug_buffer(format("highlighting recursion detected with ref to {}", m_name));
running_refs.push_back(desc);
auto pop_desc = on_scope_end([] { running_refs.pop_back(); });
try
{
DefinedHighlighters::instance().get_child(m_name).highlight(context, display_buffer, range);

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,6 @@
{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "attributes": [] }, "contents": "\"" }, { "face": { "fg": "magenta", "bg": "default", "attributes": [] }, "contents": "\"\">>> " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "\"\"\"\u000a" }]], { "fg": "default", "bg": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "attributes": [] }] }
{ "jsonrpc": "2.0", "method": "menu_hide", "params": [] }
{ "jsonrpc": "2.0", "method": "info_hide", "params": [] }
{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "out 1:1 " }, { "face": { "fg": "black", "bg": "yellow", "attributes": [] }, "contents": "" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " - unnamed0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "attributes": [] }] }
{ "jsonrpc": "2.0", "method": "set_cursor", "params": ["buffer", { "line": 0, "column": 0 }] }
{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }

View File

@ -0,0 +1 @@
""">>> """

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/core/python.kak"
set buffer filetype python