term: Bound check when setting cursor position

This commit is contained in:
mintsuki 2021-07-20 14:13:56 +02:00
parent 6e1afcd3cb
commit 0e2b9c5776
2 changed files with 20 additions and 0 deletions

View File

@ -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();
}

View File

@ -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();