]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rev: fix new line regression
authorSami Kerola <kerolasa@iki.fi>
Tue, 10 Sep 2013 19:51:14 +0000 (20:51 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Sep 2013 09:05:34 +0000 (11:05 +0200)
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@iki.fi>
text-utils/rev.c

index 85e16306b3d201cf4321a67c50654a8b3ff20c77..f1341cb3d297c764b33a05ab252a4bcb3c728c99 100644 (file)
@@ -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)) {