summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-08-03 15:31:02 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-08-03 15:31:02 +0000
commit99f4d500fdd101726e3344ca898011cab6ad5852 (patch)
treebab27216cd2a03ccf0ed54226a5e7fb4f66150ee
parentf2de0ef76255fcbc4eb988f4f6e1eef3cdd4049b (diff)
downloadcoreutils-99f4d500fdd101726e3344ca898011cab6ad5852.tar.xz
(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).
-rw-r--r--src/printenv.c18
1 files 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);
}