vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 38ae9eb88cdbaf799d554e854aad7f7745b0488f parent 602be7eba6ce2c807add13ef8db257950c3bae4a Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 15 Mar 2017 08:53:11 +0100 ui: add some bound checks Diffstat:
| M | ui-terminal.c | | | 4 | ++++ |
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/ui-terminal.c b/ui-terminal.c @@ -192,6 +192,8 @@ static bool ui_style_define(UiWin *w, int id, const char *style) { } static void ui_style(UiTerm *tui, int x, int y, int len, UiTermWin *win, enum UiStyle style_id) { + if (x < 0 || x >= tui->width || y < 0 || y >= tui->height) + return; CellStyle style = tui->styles[(win ? win->id : 0)*UI_STYLE_MAX + style_id]; Cell (*cells)[tui->width] = (void*)tui->cells; int end = x + len; @@ -203,6 +205,8 @@ static void ui_style(UiTerm *tui, int x, int y, int len, UiTermWin *win, enum Ui static void ui_draw_string(UiTerm *tui, int x, int y, const char *str, UiTermWin *win, enum UiStyle style_id) { debug("draw-string: [%d][%d]\n", y, x); + if (x < 0 || x >= tui->width || y < 0 || y >= tui->height) + return; CellStyle style = tui->styles[(win ? win->id : 0)*UI_STYLE_MAX + style_id]; // FIXME: does not handle double width characters etc, share code with view.c? Cell (*cells)[tui->width] = (void*)tui->cells;