diff options
-rw-r--r-- | src/basic/process-util.c | 58 | ||||
-rw-r--r-- | src/cryptsetup/cryptsetup.c | 1 | ||||
-rw-r--r-- | src/journal/journalctl.c | 11 | ||||
-rw-r--r-- | src/nspawn/nspawn.c | 4 | ||||
-rw-r--r-- | src/shared/install-printf.c | 6 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 5 | ||||
-rw-r--r-- | src/udev/udev-event.c | 2 |
7 files changed, 45 insertions, 42 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c index d5e7edb589..eead8b00da 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -104,7 +104,7 @@ int get_process_comm(pid_t pid, char **name) { int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line) { _cleanup_fclose_ FILE *f = NULL; bool space = false; - char *r = NULL, *k; + char *k, *ans = NULL; const char *p; int c; @@ -118,7 +118,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * * command line that resolves to the empty string will return the "comm" name of the process instead. * * Returns -ESRCH if the process doesn't exist, and -ENOENT if the process has no command line (and - * comm_fallback is false). */ + * comm_fallback is false). Returns 0 and sets *line otherwise. */ p = procfs_file_alloca(pid, "cmdline"); @@ -132,11 +132,11 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * if (max_length == 1) { /* If there's only room for one byte, return the empty string */ - r = new0(char, 1); - if (!r) + ans = new0(char, 1); + if (!ans) return -ENOMEM; - *line = r; + *line = ans; return 0; } else if (max_length == 0) { @@ -144,36 +144,36 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * while ((c = getc(f)) != EOF) { - if (!GREEDY_REALLOC(r, allocated, len+3)) { - free(r); + if (!GREEDY_REALLOC(ans, allocated, len+3)) { + free(ans); return -ENOMEM; } if (isprint(c)) { if (space) { - r[len++] = ' '; + ans[len++] = ' '; space = false; } - r[len++] = c; + ans[len++] = c; } else if (len > 0) space = true; } if (len > 0) - r[len] = 0; + ans[len] = '\0'; else - r = mfree(r); + ans = mfree(ans); } else { bool dotdotdot = false; size_t left; - r = new(char, max_length); - if (!r) + ans = new(char, max_length); + if (!ans) return -ENOMEM; - k = r; + k = ans; left = max_length; while ((c = getc(f)) != EOF) { @@ -197,20 +197,20 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * *(k++) = (char) c; left--; - } else if (k > r) + } else if (k > ans) space = true; } if (dotdotdot) { if (max_length <= 4) { - k = r; + k = ans; left = max_length; } else { - k = r + max_length - 4; + k = ans + max_length - 4; left = 4; /* Eat up final spaces */ - while (k > r && isspace(k[-1])) { + while (k > ans && isspace(k[-1])) { k--; left++; } @@ -223,11 +223,11 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * } /* Kernel threads have no argv[] */ - if (isempty(r)) { + if (isempty(ans)) { _cleanup_free_ char *t = NULL; int h; - free(r); + free(ans); if (!comm_fallback) return -ENOENT; @@ -237,22 +237,22 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * return h; if (max_length == 0) - r = strjoin("[", t, "]"); + ans = strjoin("[", t, "]"); else { size_t l; l = strlen(t); if (l + 3 <= max_length) - r = strjoin("[", t, "]"); + ans = strjoin("[", t, "]"); else if (max_length <= 6) { - r = new(char, max_length); - if (!r) + ans = new(char, max_length); + if (!ans) return -ENOMEM; - memcpy(r, "[...]", max_length-1); - r[max_length-1] = 0; + memcpy(ans, "[...]", max_length-1); + ans[max_length-1] = 0; } else { char *e; @@ -264,14 +264,14 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * e--; *e = 0; - r = strjoin("[", t, "...]"); + ans = strjoin("[", t, "...]"); } } - if (!r) + if (!ans) return -ENOMEM; } - *line = r; + *line = ans; return 0; } diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index bff5664f0f..cefd1b85df 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -750,6 +750,7 @@ int main(int argc, char *argv[]) { } else { log_error("Unknown verb %s.", argv[1]); + r = -EINVAL; goto finish; } diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 73204b3753..2a5f2b37e8 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -683,11 +683,12 @@ static int parse_argv(int argc, char *argv[]) { case ARG_VERIFY_KEY: arg_action = ACTION_VERIFY; - arg_verify_key = strdup(optarg); - if (!arg_verify_key) - return -ENOMEM; - arg_merge = false; + r = free_and_strdup(&arg_verify_key, optarg); + if (r < 0) + return r; string_erase(optarg); + + arg_merge = false; break; case ARG_INTERVAL: @@ -888,7 +889,7 @@ static int parse_argv(int argc, char *argv[]) { * to users, and automatically turn --unit= into --user-unit= if combined with --user. */ r = strv_extend_strv(&arg_user_units, arg_system_units, true); if (r < 0) - return -ENOMEM; + return r; arg_system_units = strv_free(arg_system_units); } diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 6396a69c5c..78ae2f4a0f 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -3470,8 +3470,8 @@ static int run(int master, } static int load_root_hash(const char *image) { - _cleanup_free_ char *text = NULL; - char *fn, *n, *e; + _cleanup_free_ char *text = NULL, *fn = NULL; + char *n, *e; void *k; size_t l; int r; diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c index 823fb61cda..c10ed3d311 100644 --- a/src/shared/install-printf.c +++ b/src/shared/install-printf.c @@ -93,9 +93,9 @@ static int specifier_instance(char specifier, void *data, void *userdata, char * return r; if (isempty(instance)) { - instance = strdup(i->default_instance ?: ""); - if (!instance) - return -ENOMEM; + r = free_and_strdup(&instance, i->default_instance ?: ""); + if (r < 0) + return r; } *ret = instance; diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 8955d5f51f..41e8d6075a 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -450,7 +450,7 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) { unsigned basic_len; id_len = MIN(max_id_len, 25u); /* as much as it needs, but at most 25 for now */ - basic_len = circle_len + 5 + id_len + 5 + active_len + sub_len; + basic_len = circle_len + 1 + id_len + 1 + load_len + 1 + active_len + 1 + sub_len + 1; if (job_count) basic_len += job_len + 1; @@ -472,7 +472,8 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) { id_len += incr; desc_len += MIN(extra_len - incr, max_desc_len - desc_len); } - } + } else + desc_len = 0; } else { id_len = max_id_len; desc_len = max_desc_len; diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index be7c7367ff..deffefd60b 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -213,7 +213,7 @@ subst: _s = s; _l = l; /* temporarily use sbuf */ - s = &sbuf; + s = sbuf; l = UTIL_PATH_SIZE; } |