]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/manager: silence gcc warning about unitialized variable
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 12 Feb 2017 17:56:40 +0000 (12:56 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 12 Feb 2017 17:56:40 +0000 (12:56 -0500)
At -O3, this was printed a hundred times for various callers of
manager_add_job_by_name(). AFAICT, there is no error and `unit` is always
intialized. Nevertheless, add explicit initialization to silence the noise.

src/core/manager.c: In function 'manager_start_target':
src/core/manager.c:1413:16: warning: 'unit' may be used uninitialized in this function [-Wmaybe-uninitialized]
         return manager_add_job(m, type, unit, mode, e, ret);
                ^
src/core/manager.c:1401:15: note: 'unit' was declared here
         Unit *unit;
               ^

src/core/manager.c

index 0f8f808b4a29f9576019e15f4e36dc961b55a149..5646889a8ec1d0becdd38d30c73f93ce9f82a437 100644 (file)
@@ -1398,7 +1398,7 @@ tr_abort:
 }
 
 int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, sd_bus_error *e, Job **ret) {
-        Unit *unit;
+        Unit *unit = NULL;  /* just to appease gcc, initialization is not really necessary */
         int r;
 
         assert(m);
@@ -1409,6 +1409,7 @@ int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode
         r = manager_load_unit(m, name, NULL, NULL, &unit);
         if (r < 0)
                 return r;
+        assert(unit);
 
         return manager_add_job(m, type, unit, mode, e, ret);
 }