From bca962188b113497221976a71fd18b1c11a120ab Mon Sep 17 00:00:00 2001 From: Ron Yorston <rmy@pobox.com> Date: Mon, 23 Sep 2024 11:11:14 +0100 Subject: cut: don't print empty lines with '-s' option A command like 'cut -f1 -s' would print empty lines even though they don't contain a delimiter. Add a test to avoid this. Based on a submission to the upstream mailing list: http://lists.busybox.net/pipermail/busybox/2024-July/090834.html Adds 32 bytes in 32-bit build, saves 32 in 64-bit. (GitHub issue #459) --- coreutils/cut.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/coreutils/cut.c b/coreutils/cut.c index d129f9b9d..067e69b12 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c @@ -152,6 +152,11 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, unsigned uu = 0, start = 0, end = 0, out = 0; int dcount = 0; +#if ENABLE_PLATFORM_MINGW32 + /* An empty line can't contain a delimiter */ + if (linelen == 0 && (option_mask32 & CUT_OPT_SUPPRESS_FLGS)) + goto next_line; +#endif /* Loop through bytes, finding next delimiter */ for (;;) { /* End of current range? */ -- cgit v1.2.3-55-g6feb