Skip to content

Commit c16504c

Browse files
author
Ching-Yun Liang
committed
Fix: Avoid display garbling by null-terminating display_buf
1 parent 30aa86d commit c16504c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: xo-user.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ static void listen_keyboard_handler(void)
6767
read_attr ^= 1;
6868
write(attr_fd, buf, 6);
6969
if (!read_attr)
70-
printf("Stopping to display the chess board...\n");
70+
printf("\n\nStopping to display the chess board...\n");
7171
break;
7272
case 17: /* Ctrl-Q */
7373
read(attr_fd, buf, 6);
7474
buf[4] = '1';
7575
read_attr = false;
7676
end_attr = true;
7777
write(attr_fd, buf, 6);
78-
printf("Stopping the kernel space tic-tac-toe game...\n");
78+
printf("\n\nStopping the kernel space tic-tac-toe game...\n");
7979
break;
8080
}
8181
}
@@ -117,6 +117,7 @@ int main(int argc, char *argv[])
117117
FD_CLR(device_fd, &readset);
118118
printf("\033[H\033[J"); /* ASCII escape code to clear the screen */
119119
read(device_fd, display_buf, DRAWBUFFER_SIZE);
120+
display_buf[DRAWBUFFER_SIZE - 1] = '\0';
120121
printf("%s", display_buf);
121122
}
122123
}

0 commit comments

Comments
 (0)