From 8ed5403d8c673fcdeb13a9b8e365a3f54a24cd49 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 13 Sep 2022 16:15:53 +0100 Subject: [PATCH] comm: Stop skipping a line in the output Because of how we output lines in the loop above, if we leave that loop when the last line was not the same in both files, then either `file1_line` or `file2_line` has not been output yet. `process_remaining()` does not print that line either, since it immediately reads a new line. So, output the previously-missing line before we call that. :^) --- Userland/Utilities/comm.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Userland/Utilities/comm.cpp b/Userland/Utilities/comm.cpp index 677b6bf672..08142442ec 100644 --- a/Userland/Utilities/comm.cpp +++ b/Userland/Utilities/comm.cpp @@ -141,6 +141,16 @@ ErrorOr serenity_main(Main::Arguments arguments) } } + // If the most recent line read was not a match, then the last line read from one of the files has not yet been output. + // So let's output it! + if (!read_file1 && !suppress_col1) { + ++col1_count; + outln(col1_fmt, file1_line); + } else if (!read_file2 && !suppress_col2) { + ++col2_count; + outln(col2_fmt, file2_line); + } + process_remaining(col1_fmt, file1, col1_count, !suppress_col1); process_remaining(col2_fmt, file2, col2_count, !suppress_col2);