From: Sami Kerola Date: Sun, 2 Jun 2013 17:51:17 +0000 (+0100) Subject: rev: simplify new line detection and impossible test X-Git-Tag: v2.24-rc1~509 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2e081ce0f81f6c4d6601665bfa447da28973bf3;p=thirdparty%2Futil-linux.git 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 --- diff --git a/text-utils/rev.c b/text-utils/rev.c index 0456c2b144..1665772b24 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'); }