From 978dfa5e02acfcc35b9f31b9c88255c79ebcfb54 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 26 May 2025 21:38:18 -0400 Subject: kernel: cons: Fix newline caused by excessive '\b' Before this commit, if you were to write out too many backspace characters, it would result in an integer underflow for the scr->curs_col and scr->ch_col state resulting in the console logic assuming the cursor has gone too far off the screen which would cause behavior similar to as if you wrote out a line-feed character. Signed-off-by: Ian Moffett --- sys/dev/cons/cons.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/dev/cons/cons.c b/sys/dev/cons/cons.c index bcd19bf..61254a7 100644 --- a/sys/dev/cons/cons.c +++ b/sys/dev/cons/cons.c @@ -165,8 +165,10 @@ cons_handle_special(struct cons_screen *scr, char c) } HIDE_CURSOR(scr); - --scr->ch_col; - --scr->curs_col; + if (scr->ch_col > 0 && scr->curs_col > 0) { + --scr->ch_col; + --scr->curs_col; + } SHOW_CURSOR(scr); return 0; case ASCII_LF: -- cgit v1.2.3