From c73947814aab381a0761ecc919e6c5407c3fd617 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 14 Apr 2016 21:00:54 -0500 Subject: Andy Chu pointed out an out of bounds access for zero length lines. While we're at it, use unsigned for the line length. --- toys/other/rev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toys/other/rev.c') diff --git a/toys/other/rev.c b/toys/other/rev.c index 4cf7214f..15066310 100644 --- a/toys/other/rev.c +++ b/toys/other/rev.c @@ -20,11 +20,11 @@ static void do_rev(int fd, char *name) char *c; for (;;) { - int len, i; + unsigned len, i; if (!(c = get_line(fd))) break; - len = strlen(c) - 1; - for (i = 0; i <= len/2; i++) { + len = strlen(c); + if (len--) for (i = 0; i <= len/2; i++) { char tmp = c[i]; c[i] = c[len-i]; -- cgit v1.2.3