Fix compute_pos behaviour not to overflow by one line

Thanks to eraserhd for debugging this and proposing an initial fix.

Fixes #3414
Close #3418
This commit is contained in:
Maxime Coste 2020-03-20 20:31:09 +11:00
parent 5466f63eeb
commit 0506de8443

View File

@ -124,6 +124,7 @@ struct TerminalUI::Window::Line
void TerminalUI::Window::blit(Window& target)
{
kak_assert(pos.line + lines.size() <= target.lines.size());
auto target_line = target.lines.begin() + (size_t)pos.line;
for (auto& line : lines)
{
@ -1030,10 +1031,10 @@ static DisplayCoord compute_pos(DisplayCoord anchor, DisplayCoord size,
if (not prefer_above)
{
pos = anchor + DisplayCoord{1_line};
if (pos.line + size.line > rect_end.line)
if (pos.line + size.line >= rect_end.line)
pos.line = max(rect.pos.line, anchor.line - size.line);
}
if (pos.column + size.column > rect_end.column)
if (pos.column + size.column >= rect_end.column)
pos.column = max(rect.pos.column, rect_end.column - size.column);
if (to_avoid.size != DisplayCoord{})