From a05294ff05923563087b53c1db64816130be3b34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Feb 2019 11:29:38 +0100 Subject: [PATCH] shared/install: do not use a temporary variable outside of its scope 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 | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/shared/install.c b/src/shared/install.c index 9e88ac46bd..64d55532e2 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -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); } -- 2.25.1