From 59f016cba14be2578ea4695d4f7ee7bbe4c354c4 Mon Sep 17 00:00:00 2001 From: Ching-Yun Liang Date: Mon, 14 Apr 2025 13:34:35 +0800 Subject: [PATCH] Avoid display garbling Ensures the display buffer is null-terminated This prevents garbled output when printing the buffer. --- xo-user.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xo-user.c b/xo-user.c index 4e567de..791b721 100644 --- a/xo-user.c +++ b/xo-user.c @@ -67,7 +67,7 @@ static void listen_keyboard_handler(void) read_attr ^= 1; write(attr_fd, buf, 6); if (!read_attr) - printf("Stopping to display the chess board...\n"); + printf("\n\nStopping to display the chess board...\n"); break; case 17: /* Ctrl-Q */ read(attr_fd, buf, 6); @@ -75,7 +75,7 @@ static void listen_keyboard_handler(void) read_attr = false; end_attr = true; write(attr_fd, buf, 6); - printf("Stopping the kernel space tic-tac-toe game...\n"); + printf("\n\nStopping the kernel space tic-tac-toe game...\n"); break; } } @@ -117,6 +117,7 @@ int main(int argc, char *argv[]) FD_CLR(device_fd, &readset); printf("\033[H\033[J"); /* ASCII escape code to clear the screen */ read(device_fd, display_buf, DRAWBUFFER_SIZE); + display_buf[DRAWBUFFER_SIZE - 1] = '\0'; printf("%s", display_buf); } }