From: Zbigniew Jędrzejewski-Szmek Date: Thu, 28 Feb 2019 10:29:38 +0000 (+0100) Subject: shared/install: do not use a temporary variable outside of its scope X-Git-Tag: v242-rc1~221^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a05294ff05923563087b53c1db64816130be3b34;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/shared/install.c b/src/shared/install.c index 9e88ac46bd5..64d55532e29 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); }