From 6298ca94cbc4685d46d7d451c54889ababc6782b Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Tue, 17 Jun 2008 21:58:46 +0000 Subject: [PATCH] * libmisc/env.c: Avoid implicit conversion of pointers / chars to booleans. * libmisc/env.c: Add brackets and parenthesis. * libmisc/env.c: Ignore the return value of puts() and fputs(). * libmisc/env.c: Avoid multi-statements lines. --- ChangeLog | 8 ++++++++ libmisc/env.c | 54 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ba2cd67..f20c53ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-06-17 Nicolas François + + * libmisc/env.c: Avoid implicit conversion of pointers / chars to + booleans. + * libmisc/env.c: Add brackets and parenthesis. + * libmisc/env.c: Ignore the return value of puts() and fputs(). + * libmisc/env.c: Avoid multi-statements lines. + 2008-06-17 Nicolas François * libmisc/utmp.c: Avoid implicit conversion of pointers / chars to diff --git a/libmisc/env.c b/libmisc/env.c index da03ac4e..e982f731 100644 --- a/libmisc/env.c +++ b/libmisc/env.c @@ -91,7 +91,7 @@ void addenv (const char *string, const char *value) size_t i; size_t n; - if (value) { + if (NULL != value) { newstring = xmalloc (strlen (string) + strlen (value) + 2); sprintf (newstring, "%s=%s", string, value); } else { @@ -104,7 +104,7 @@ void addenv (const char *string, const char *value) */ cp = strchr (newstring, '='); - if (!cp) { + if (NULL == cp) { free (newstring); return; } @@ -112,9 +112,10 @@ void addenv (const char *string, const char *value) n = (size_t) (cp - newstring); for (i = 0; i < newenvc; i++) { - if (strncmp (newstring, newenvp[i], n) == 0 && - (newenvp[i][n] == '=' || newenvp[i][n] == '\0')) + if ( (strncmp (newstring, newenvp[i], n) == 0) + && (('=' == newenvp[i][n]) || ('\0' == newenvp[i][n]))) { break; + } } if (i < newenvc) { @@ -151,12 +152,14 @@ void addenv (const char *string, const char *value) * environ so that it doesn't point to some * free memory area (realloc() could move it). */ - if (environ == newenvp) + if (environ == newenvp) { environ = __newenvp; + } newenvp = __newenvp; } else { - fputs (_("Environment overflow\n"), stderr); - free (newenvp[--newenvc]); + (void) fputs (_("Environment overflow\n"), stderr); + newenvc--; + free (newenvp[newenvc]); } } @@ -178,21 +181,25 @@ void set_env (int argc, char *const *argv) char *cp; for (; argc > 0; argc--, argv++) { - if (strlen (*argv) >= sizeof variable) + if (strlen (*argv) >= sizeof variable) { continue; /* ignore long entries */ + } - if (!(cp = strchr (*argv, '='))) { + cp = strchr (*argv, '='); + if (NULL == cp) { snprintf (variable, sizeof variable, "L%d", noname++); addenv (variable, *argv); } else { const char **p; - for (p = forbid; *p; p++) - if (strncmp (*argv, *p, strlen (*p)) == 0) + for (p = forbid; NULL != *p; p++) { + if (strncmp (*argv, *p, strlen (*p)) == 0) { break; + } + } - if (*p) { - strncpy (variable, *argv, cp - *argv); + if (NULL != *p) { + strncpy (variable, *argv, (size_t)(cp - *argv)); variable[cp - *argv] = '\0'; printf (_("You may not change $%s\n"), variable); @@ -220,27 +227,32 @@ void sanitize_env (void) char **cur; char **move; - for (cur = envp; *cur; cur++) { - for (bad = forbid; *bad; bad++) { + for (cur = envp; NULL != *cur; cur++) { + for (bad = forbid; NULL != *bad; bad++) { if (strncmp (*cur, *bad, strlen (*bad)) == 0) { - for (move = cur; *move; move++) + for (move = cur; NULL != *move; move++) { *move = *(move + 1); + } cur--; break; } } } - for (cur = envp; *cur; cur++) { - for (bad = noslash; *bad; bad++) { - if (strncmp (*cur, *bad, strlen (*bad)) != 0) + for (cur = envp; NULL != *cur; cur++) { + for (bad = noslash; NULL != *bad; bad++) { + if (strncmp (*cur, *bad, strlen (*bad)) != 0) { continue; - if (!strchr (*cur, '/')) + } + if (strchr (*cur, '/') != NULL) { continue; /* OK */ - for (move = cur; *move; move++) + } + for (move = cur; NULL != *move; move++) { *move = *(move + 1); + } cur--; break; } } } +