Skip to content

Commit

Permalink
utils: poll: process lines that might just be missing a carriage return
Browse files Browse the repository at this point in the history
  • Loading branch information
connorimes committed Apr 3, 2024
1 parent ec4221b commit 16c9013
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion utils/osp3-poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 16c9013

Please sign in to comment.