From fa9cde45aae254aae843a96442083019ddd5d895 Mon Sep 17 00:00:00 2001 From: "Liam J. Foy" Date: Wed, 8 Dec 2004 20:17:12 +0000 Subject: [PATCH] - We should always check the setenv() call. Why? because it uses both realloc and malloc. - Remove unnecessary casts. - Bump WARNS to 6 --- usr.bin/env/Makefile | 4 ++-- usr.bin/env/env.c | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/usr.bin/env/Makefile b/usr.bin/env/Makefile index 945672c42e..13e7327d90 100644 --- a/usr.bin/env/Makefile +++ b/usr.bin/env/Makefile @@ -1,9 +1,9 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD: src/usr.bin/env/Makefile,v 1.2.6.1 2001/08/02 02:25:58 obrien Exp $ -# $DragonFly: src/usr.bin/env/Makefile,v 1.2 2003/06/17 04:29:26 dillon Exp $ +# $DragonFly: src/usr.bin/env/Makefile,v 1.3 2004/12/08 20:17:12 liamfoy Exp $ PROG= env -WARNS?= 2 +WARNS?= 6 NOMAN= noman .include diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c index 1a3e4526c7..ebefd7b2a8 100644 --- a/usr.bin/env/env.c +++ b/usr.bin/env/env.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1988, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)env.c 8.3 (Berkeley) 4/2/94 * $FreeBSD: src/usr.bin/env/env.c,v 1.5.2.3 2002/06/26 08:23:36 tjr Exp $ - * $DragonFly: src/usr.bin/env/env.c,v 1.3 2003/10/04 20:36:43 hmp Exp $ + * $DragonFly: src/usr.bin/env/env.c,v 1.4 2004/12/08 20:17:12 liamfoy Exp $ */ #include @@ -61,25 +61,27 @@ main(int argc, char **argv) environ = cleanenv; cleanenv[0] = NULL; break; - case '?': default: usage(); } - for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) - (void)setenv(*argv, ++p, 1); + for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) { + if (setenv(*argv, ++p, 1) == -1) + err(1, "%s", *argv); + } + if (*argv) { execvp(*argv, argv); err(errno == ENOENT ? 127 : 126, "%s", *argv); } for (ep = environ; *ep; ep++) - (void)printf("%s\n", *ep); + printf("%s\n", *ep); exit(0); } static void usage(void) { - (void)fprintf(stderr, - "usage: env [-] [-i] [name=value ...] [utility [argument ...]]\n"); + fprintf(stderr, + "usage: env [-i] [name=value ...] [utility [argument ...]]\n"); exit(1); } -- 2.41.0