test-capability: silence gcc warning

[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
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-03-31 18:24:53 +02:00
parent bc20c31bbc
commit 0a94e77ed4
+5 -12
View File
@@ -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);