From 99f4d500fdd101726e3344ca898011cab6ad5852 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 3 Aug 2004 15:31:02 +0000 Subject: (main): Use bool for booleans. Do not assume that the environ has at most one matching entry for each option (integer overflow was possible otherwise). --- src/printenv.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/printenv.c b/src/printenv.c index 2545d46ff..1ad281994 100644 --- a/src/printenv.c +++ b/src/printenv.c @@ -83,9 +83,8 @@ main (int argc, char **argv) char **env; char *ep, *ap; int i; - int matches = 0; int c; - int exit_status; + bool ok; initialize_main (&argc, &argv); program_name = argv[0]; @@ -115,12 +114,16 @@ main (int argc, char **argv) { for (env = environ; *env != NULL; ++env) puts (*env); - exit_status = EXIT_SUCCESS; + ok = true; } else { + int matches = 0; + for (i = optind; i < argc; ++i) { + bool matched = false; + for (env = environ; *env; ++env) { ep = *env; @@ -130,14 +133,17 @@ main (int argc, char **argv) if (*ep == '=' && *ap == '\0') { puts (ep + 1); - ++matches; + matched = true; break; } } } + + matches += matched; } - exit_status = (matches != argc - optind); + + ok = (matches == argc - optind); } - exit (exit_status); + exit (ok ? EXIT_SUCCESS : EXIT_FAILURE); } -- cgit v1.2.3-70-g09d2