From 00844efd2ff16d43299fd54c78f8483c642c693a Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 30 May 2024 15:10:23 +0200 Subject: [PATCH] test/terminal_expect_send: warn on excess chars This patch adds a warning on the occurrence of overly long lines and drops characters in this case. Fixes #5108 --- repos/os/src/test/terminal_expect_send/main.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/repos/os/src/test/terminal_expect_send/main.cc b/repos/os/src/test/terminal_expect_send/main.cc index 185e69d09e..7d64a8939a 100644 --- a/repos/os/src/test/terminal_expect_send/main.cc +++ b/repos/os/src/test/terminal_expect_send/main.cc @@ -34,14 +34,21 @@ struct Main void handle_read_avail() { - size_t num_bytes = terminal.read(read_buffer, sizeof(read_buffer)); + size_t const num_bytes = terminal.read(read_buffer, sizeof(read_buffer)); for (size_t i = 0; i < num_bytes; i++) { + char const c = read_buffer[i]; + /* copy over all characters other than line-end */ - if (read_buffer[i] != '\n' && - read_buffer[i] != '\r') { - line[line_idx++] = read_buffer[i]; + if (c != '\n' && c != '\r') { + line[line_idx++] = c; + + if (line_idx >= MAX_LINE_LENGTH) { + warning("dropping characters (maximum line length exceeded)"); + line_idx = 0; + } + line[line_idx] = 0; } @@ -52,7 +59,7 @@ struct Main } /* check for line end */ - if (read_buffer[i] == '\n') { + if (c == '\n') { if (verbose) log(Cstring(line)); line_idx = 0; line[line_idx] = 0;