From 00d4b1e684a84cf87f5694f30ad69afc19ada166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 25 Feb 2018 17:26:22 +0100 Subject: [PATCH] basic: shorten the code a bit in two places gcc complains that len might be used unitialized, but afaict, this is not true. --- src/basic/cgroup-util.c | 4 +--- src/basic/env-util.c | 22 +++++++--------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 7c0ba921104..52ae37e6b42 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -1062,13 +1062,11 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) { continue; *e = 0; - FOREACH_WORD_SEPARATOR(word, k, l, ",", state) { + FOREACH_WORD_SEPARATOR(word, k, l, ",", state) if (k == cs && memcmp(word, controller_str, cs) == 0) { found = true; break; } - } - if (!found) continue; } diff --git a/src/basic/env-util.c b/src/basic/env-util.c index e77f9d6d3fd..ab3fc71cd2b 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -539,8 +539,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { assert(format); - for (e = format, i = 0; *e && i < n; e ++, i ++) { - + for (e = format, i = 0; *e && i < n; e ++, i ++) switch (state) { case WORD: @@ -554,8 +553,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { if (!k) return NULL; - free(r); - r = k; + free_and_replace(r, k); word = e-1; state = VARIABLE; @@ -565,8 +563,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { if (!k) return NULL; - free(r); - r = k; + free_and_replace(r, k); word = e+1; state = WORD; @@ -576,8 +573,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { if (!k) return NULL; - free(r); - r = k; + free_and_replace(r, k); word = e-1; state = VARIABLE_RAW; @@ -596,8 +592,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { if (!k) return NULL; - free(r); - r = k; + free_and_replace(r, k); word = e+1; state = WORD; @@ -653,8 +648,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { if (!k) return NULL; - free(r); - r = k; + free_and_replace(r, k); word = e+1; state = WORD; @@ -673,8 +667,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { if (!k) return NULL; - free(r); - r = k; + free_and_replace(r, k); word = e--; i--; @@ -682,7 +675,6 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { } break; } - } if (state == VARIABLE_RAW) { const char *t;