[PATCH 2/2] rev: fix new line regression

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit 4b4eb34004378fe70259acd8f2f859e7b5cc3726 made output incorrect for
input lines that does not have new line.  For example

$ printf "a b c\n1 2 3" | rev
c b a
 2 13

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 text-utils/rev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/text-utils/rev.c b/text-utils/rev.c
index 85e1630..f1341cb 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -163,7 +163,9 @@ int main(int argc, char *argv[])
 
 				len = wcslen(buf);
 			}
-			reverse_str(buf, len - 1);
+			if (buf[len - 1] == '\n')
+				buf[len--] = '\0';
+			reverse_str(buf, len);
 			fputws(buf, stdout);
 		}
 		if (ferror(fp)) {
-- 
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux