public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 2/2] rev: fix new line regression
Date: Tue, 10 Sep 2013 20:51:14 +0100	[thread overview]
Message-ID: <1378842674-456-2-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1378842674-456-1-git-send-email-kerolasa@iki.fi>

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 | 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


  reply	other threads:[~2013-09-10 19:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-10 19:51 [PATCH 1/2] tests: lscpu: add CPU max MHz to test results Sami Kerola
2013-09-10 19:51 ` Sami Kerola [this message]
2013-09-12  9:06   ` [PATCH 2/2] rev: fix new line regression Karel Zak
2013-09-12  9:05 ` [PATCH 1/2] tests: lscpu: add CPU max MHz to test results Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1378842674-456-2-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox