From 16c9013270ac66fc087f760f077a0df42b945194 Mon Sep 17 00:00:00 2001 From: Connor Imes Date: Wed, 3 Apr 2024 18:42:47 -0400 Subject: [PATCH] utils: poll: process lines that might just be missing a carriage return --- utils/osp3-poll.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/osp3-poll.c b/utils/osp3-poll.c index ac66053..52c89e5 100644 --- a/utils/osp3-poll.c +++ b/utils/osp3-poll.c @@ -195,7 +195,10 @@ static int osp3_poll(osp3_device* dev) { } assert(line_written > 0); assert(line[line_written - 1] == '\n'); - if (line_written < OSP3_LOG_PROTOCOL_SIZE) { + // If the line came from the serial port, we should expect `line_written == OSP3_LOG_PROTOCOL_SIZE`. + // However, a line from stdin may not include the '\r' prior to the '\n', so we'll try to be forgiving. + // Parsing and checksum should still drop bad messages (unless disabled, but that's the user being reckless). + if (line_written < OSP3_LOG_PROTOCOL_SIZE - 1) { fprintf(stderr, "Dropping shorter line than expected: %s", line); } else if (line_written > OSP3_LOG_PROTOCOL_SIZE) { fprintf(stderr, "Dropping longer line than expected: %s", line);