]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: Workaround -Wnonnull GCC bug
authorBenjamin Robin <dev@benjarobin.fr>
Wed, 6 May 2020 19:24:05 +0000 (21:24 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 May 2020 07:43:28 +0000 (09:43 +0200)
See issue #6119

src/core/manager.c
src/shared/install.c

index 501e37339b82f903dd22fe12199ca895b8f826c1..7c207bed6e70c442f810c89f5706ac2834c8f630 100644 (file)
@@ -1968,7 +1968,6 @@ int manager_load_unit_prepare(
         int r;
 
         assert(m);
-        assert(name || path);
         assert(_ret);
 
         /* This will prepare the unit for loading, but not actually
@@ -1977,8 +1976,13 @@ int manager_load_unit_prepare(
         if (path && !is_path(path))
                 return sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not absolute.", path);
 
-        if (!name)
+        if (!name) {
+                /* 'name' and 'path' must not both be null. Check here 'path' using assert_se() to
+                 * workaround a bug in gcc that generates a -Wnonnull warning when calling basename(),
+                 * but this cannot be possible in any code path (See #6119). */
+                assert_se(path);
                 name = basename(path);
+        }
 
         t = unit_name_to_type(name);
 
index ec2b99ab98d855f882fb9cc84b970bda4860f1cc..21ad5aab36a6bc0485efd26f601bf521c911e13c 100644 (file)
@@ -1013,10 +1013,14 @@ static int install_info_add(
         int r;
 
         assert(c);
-        assert(name || path);
 
-        if (!name)
+        if (!name) {
+                /* 'name' and 'path' must not both be null. Check here 'path' using assert_se() to
+                 * workaround a bug in gcc that generates a -Wnonnull warning when calling basename(),
+                 * but this cannot be possible in any code path (See #6119). */
+                assert_se(path);
                 name = basename(path);
+        }
 
         if (!unit_name_is_valid(name, UNIT_NAME_ANY))
                 return -EINVAL;