]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: modernize asprintf error handling
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 2 Jul 2021 14:48:56 +0000 (16:48 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 Jul 2021 09:33:44 +0000 (11:33 +0200)
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().

src/core/manager.c

index 72f1e109d79365e23a8ecc350581a8e5d230a925..594be370c65d8398f6f85f9cd0c2b0074ee37ad1 100644 (file)
@@ -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)