From 0a94e77ed4cf5480f2ea0aac373392a9bb48571d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 31 Mar 2021 17:13:24 +0200 Subject: [PATCH] test-capability: silence gcc warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit [2/3] Compiling C object test-capability.p/src_test_test-capability.c.o ../src/test/test-capability.c: In function ‘main’: ../src/test/test-capability.c:270:12: warning: ‘run_ambient’ may be used uninitialized in this function [-Wmaybe-uninitialized] 270 | if (run_ambient) | ^ gcc-11.0.1-0.3.fc34.x86_64 --- src/test/test-capability.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/test/test-capability.c b/src/test/test-capability.c index 0ff56070b16..bd17dc0e790 100644 --- a/src/test/test-capability.c +++ b/src/test/test-capability.c @@ -103,22 +103,15 @@ static int setup_tests(bool *run_ambient) { nobody = getpwnam(NOBODY_USER_NAME); if (!nobody) - return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Could not find nobody user: %m"); + return log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Couldn't find 'nobody' user: %m"); test_uid = nobody->pw_uid; test_gid = nobody->pw_gid; - *run_ambient = false; - r = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0); - - /* There's support for PR_CAP_AMBIENT if the prctl() call - * succeeded or error code was something else than EINVAL. The - * EINVAL check should be good enough to rule out false - * positives. */ - - if (r >= 0 || errno != EINVAL) - *run_ambient = true; + /* There's support for PR_CAP_AMBIENT if the prctl() call succeeded or error code was something else + * than EINVAL. The EINVAL check should be good enough to rule out false positives. */ + *run_ambient = r >= 0 || errno != EINVAL; return 0; } @@ -249,7 +242,7 @@ static void test_ensure_cap_64bit(void) { } int main(int argc, char *argv[]) { - bool run_ambient; + bool run_ambient = false; /* unnecessary initialization to silence gcc warning */ test_setup_logging(LOG_INFO); -- 2.47.3