[PATCH 11/19] rev: simplify new line detection and impossible test

Sami Kerola
2013-06-02T17:52:09Z

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 | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/text-utils/rev.c b/text-utils/rev.c
index 0456c2b..1665772 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');
}
--
1.8.3