]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/install: do not use a temporary variable outside of its scope
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 28 Feb 2019 10:29:38 +0000 (11:29 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 28 Feb 2019 10:29:38 +0000 (11:29 +0100)
Coverity says:
> Pointer to local outside scope (RETURN_LOCAL)9.
> use_invalid: Using dirs, which points to an out-of-scope temporary variable of type char const *[5].

And indeed, the switch statement forms a scope. Let's use an if to
avoid creating a scope.

src/shared/install.c

index 9e88ac46bd50b2acc7c21695bd9b69bc1c2754f7..64d55532e299f4e19a4278162b94d46739be21bc 100644 (file)
@@ -2827,19 +2827,14 @@ static int presets_find_config(UnitFileScope scope, const char *root_dir, char *
         assert(scope >= 0);
         assert(scope < _UNIT_FILE_SCOPE_MAX);
 
-        switch (scope) {
-        case UNIT_FILE_SYSTEM:
+        if (scope == UNIT_FILE_SYSTEM)
                 dirs = (const char* const*) CONF_PATHS_STRV("systemd/system-preset");
-                break;
 
-        case UNIT_FILE_GLOBAL:
-        case UNIT_FILE_USER:
+        else if (IN_SET(scope, UNIT_FILE_GLOBAL, UNIT_FILE_USER))
                 dirs = (const char* const*) CONF_PATHS_USR_STRV("systemd/user-preset");
-                break;
 
-        default:
+        else
                 assert_not_reached("Invalid unit file scope");
-        }
 
         return conf_files_list_strv(files, ".preset", root_dir, 0, dirs);
 }