From ad9a9dd3e10629f82c89dcdbf2070f4efb23738f Mon Sep 17 00:00:00 2001 From: FRIGN Date: Sat, 28 Feb 2015 21:11:10 +0100 Subject: [PATCH] Audit yes(1) Oh well, time to simplify the loop. Also, change the comment on unreachable code to something more clear. --- yes.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/yes.c b/yes.c index 0ac224a..eddc0f0 100644 --- a/yes.c +++ b/yes.c @@ -19,14 +19,10 @@ main(int argc, char *argv[]) usage(); } ARGEND; - if (argc == 0) { - for (;;) - puts("y"); - } else { - for (i = 0; ; i++, i %= argc) { - printf("%s", argv[i]); - putchar(i == argc - 1 ? '\n' : ' '); - } + for (i = 0; ; i++, i %= argc ? argc : 1) { + fputs(argc ? argv[i] : "y", stdout); + putchar((!argc || i == argc - 1) ? '\n' : ' '); } - return 1; /* should not reach */ + + return 1; /* not reached */ }