]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rev: simplify new line detection and impossible test
authorSami Kerola <kerolasa@iki.fi>
Sun, 2 Jun 2013 17:51:17 +0000 (18:51 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Jun 2013 10:24:47 +0000 (12:24 +0200)
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 <kerolasa@iki.fi>
text-utils/rev.c

index 0456c2b144c63f309ab37c4fe9085e17d5b5fef3..1665772b24919fd5319b4686c28fc4b9b6be224d 100644 (file)
@@ -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');
                }