term: Bound check when setting cursor position
diff --git a/stage23/drivers/vga_textmode.s2.c b/stage23/drivers/vga_textmode.s2.c
index bac86010..18048f76 100644
--- a/stage23/drivers/vga_textmode.s2.c
+++ b/stage23/drivers/vga_textmode.s2.c
@@ -176,6 +176,16 @@ void text_get_cursor_pos(int *x, int *y) {
void text_set_cursor_pos(int x, int y) {
clear_cursor();
+ if (x < 0) {
+ x = 0;
+ } else if (x >= VD_COLS / 2) {
+ x = VD_COLS / 2 - 1;
+ }
+ if (y < 0) {
+ y = 0;
+ } else if (y >= VD_ROWS) {
+ 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 7f08eacf..6aca3a82 100644
--- a/stage23/lib/gterm.c
+++ b/stage23/lib/gterm.c
@@ -356,6 +356,16 @@ bool gterm_disable_cursor(void) {
void gterm_set_cursor_pos(int x, int y) {
clear_cursor();
+ if (x < 0) {
+ x = 0;
+ } else if (x >= cols) {
+ x = cols - 1;
+ }
+ if (y < 0) {
+ y = 0;
+ } else if (y >= rows) {
+ y = rows - 1;
+ }
cursor_x = x;
cursor_y = y;
draw_cursor();
