aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-03-15 08:53:11 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-03-15 09:26:34 +0100
commit702a97e296f95ca1fc7ff2e0002d2e97366a86db (patch)
tree21fd1482f84873cfc67f8c182875b518623bc98d
parentfbf5c1b6eda2ca196132b510bc73face8a1e5c46 (diff)
downloadvis-702a97e296f95ca1fc7ff2e0002d2e97366a86db.tar.gz
vis-702a97e296f95ca1fc7ff2e0002d2e97366a86db.tar.xz
ui: add some bound checks
-rw-r--r--ui-terminal.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/ui-terminal.c b/ui-terminal.c
index 3b9ac3b..a15f9dd 100644
--- 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;