From b2e081ce0f81f6c4d6601665bfa447da28973bf3 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 2 Jun 2013 18:51:17 +0100 Subject: rev: simplify new line detection and impossible test The new line detection is earlier using only '\n' so there should not be need to search for '\r' later. The detection whether allocated address is pointing to null seems to be unnecessary. Assuming xmalloc() returned valid address space the address should never be 0. Signed-off-by: Sami Kerola --- text-utils/rev.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'text-utils/rev.c') diff --git a/text-utils/rev.c b/text-utils/rev.c index 0456c2b14..1665772b2 100644 --- a/text-utils/rev.c +++ b/text-utils/rev.c @@ -154,11 +154,10 @@ int main(int argc, char *argv[]) len = wcslen(buf); } - t = buf + len - 1 - (*(buf+len-1)=='\r' || *(buf+len-1)=='\n'); - for ( ; t >= buf; --t) { - if (*t != 0) - putwchar(*t); - } + if (*(t = buf + len - 1) == '\n') + --t; + for ( ; buf <= t; --t) + putwchar(*t); if (!feof(fp)) putwchar('\n'); } -- cgit v1.2.3-55-g7522