From 7ad45e8daf6e2c4ff5d62207383abdafaf4aa072 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sat, 11 Sep 2021 08:43:39 +0200 Subject: [PATCH] term: Fix bug introduced when moving from int to size_t for coordinates. Fixes #110 --- stage23/drivers/vga_textmode.s2.c | 12 ++++++++++-- stage23/lib/gterm.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/stage23/drivers/vga_textmode.s2.c b/stage23/drivers/vga_textmode.s2.c index 075a5dda..d48c6ea9 100644 --- a/stage23/drivers/vga_textmode.s2.c +++ b/stage23/drivers/vga_textmode.s2.c @@ -242,10 +242,18 @@ void text_move_character(size_t new_x, size_t new_y, size_t old_x, size_t old_y) void text_set_cursor_pos(size_t x, size_t y) { clear_cursor(); if (x >= VD_COLS / 2) { - x = VD_COLS / 2 - 1; + if ((int)x < 0) { + x = 0; + } else { + x = VD_COLS / 2 - 1; + } } if (y >= VD_ROWS) { - y = VD_ROWS - 1; + if ((int)y < 0) { + y = 0; + } else { + y = VD_ROWS - 1; + } } cursor_offset = y * VD_COLS + x * 2; draw_cursor(); diff --git a/stage23/lib/gterm.c b/stage23/lib/gterm.c index 5c3804f1..ca2310b0 100644 --- a/stage23/lib/gterm.c +++ b/stage23/lib/gterm.c @@ -416,10 +416,18 @@ bool gterm_disable_cursor(void) { void gterm_set_cursor_pos(size_t x, size_t y) { clear_cursor(); if (x >= cols) { - x = cols - 1; + if ((int)x < 0) { + x = 0; + } else { + x = cols - 1; + } } if (y >= rows) { - y = rows - 1; + if ((int)y < 0) { + y = 0; + } else { + y = rows - 1; + } } cursor_x = x; cursor_y = y;