diff options
Diffstat (limited to 'coreutils/printenv.c')
-rw-r--r-- | coreutils/printenv.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/coreutils/printenv.c b/coreutils/printenv.c index 33be5c0..d0fb716 100644 --- a/coreutils/printenv.c +++ b/coreutils/printenv.c @@ -19,9 +19,14 @@ int printenv_main(int argc UNUSED_PARAM, char **argv) /* no variables specified, show whole env */ if (!argv[1]) { - int e = 0; - while (environ[e]) - puts(environ[e++]); + char **e = environ; + + /* environ can be NULL! (for example, after clearenv()) + * Check for that: + */ + if (e) + while (*e) + puts(*e++); } else { /* search for specified variables and print them out if found */ char *arg, *env; |