[hackers] [sbase] Audit yes(1) || FRIGN

From: <git_AT_suckless.org>
Date: Sat, 28 Feb 2015 22:12:22 +0100 (CET)

commit f0792e41e8654edfba4485ed84b9448010cb7f9d
Author: FRIGN <dev_AT_frign.de>
Date: Sat Feb 28 21:11:10 2015 +0100

    Audit yes(1)
    
    Oh well, time to simplify the loop.
    Also, change the comment on unreachable code to something more clear.

diff --git a/yes.c b/yes.c
index 0ac224a..eddc0f0 100644
--- a/yes.c
+++ b/yes.c
_AT_@ -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 */
 }
Received on Sat Feb 28 2015 - 22:12:22 CET

This archive was generated by hypermail 2.3.0 : Sat Feb 28 2015 - 22:24:10 CET