From: Zbigniew Jędrzejewski-Szmek Date: Fri, 2 Jul 2021 14:48:56 +0000 (+0200) Subject: core: modernize asprintf error handling X-Git-Tag: v250-rc1~933^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=305757d80819873c8918c6ea229f96fc10b77696;p=thirdparty%2Fsystemd.git core: modernize asprintf error handling The man page says asprintf() pointer is "undefined" on error, but the only meaningful interpretation is that it's either NULL or points to something that should be freed with free(). --- diff --git a/src/core/manager.c b/src/core/manager.c index 72f1e109d79..594be370c65 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -230,8 +230,7 @@ static void manager_print_jobs_in_progress(Manager *m) { m->jobs_in_progress_iteration++; if (m->n_running_jobs > 1) - if (asprintf(&job_of_n, "(%u of %u) ", counter, m->n_running_jobs) < 0) - job_of_n = NULL; + (void) asprintf(&job_of_n, "(%u of %u) ", counter, m->n_running_jobs); bool have_timeout = job_get_timeout(j, &x) > 0; @@ -620,9 +619,7 @@ static char** sanitize_environment(char **l) { NULL); /* Let's order the environment alphabetically, just to make it pretty */ - strv_sort(l); - - return l; + return strv_sort(l); } int manager_default_environment(Manager *m) { @@ -3142,10 +3139,8 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) { return; } - if (asprintf(&message, "U\002%c%s%n", (int) (strlen(u->id) + 1), u->id, &n) < 0) { - log_oom(); - return; - } + if (asprintf(&message, "U\002%c%s%n", (int) (strlen(u->id) + 1), u->id, &n) < 0) + return (void) log_oom(); errno = 0; if (write(fd, message, n + 1) != n + 1)