Fix clang-tidy issues in C++ code * Use `uid_t` for `getuid` return value. * Actually report errors returned by `posix_*` functions, which never return a negative value. Closes #24026. PiperOrigin-RevId: 689373027 Change-Id: I3b7b515cb0043a010268af231bbc6f5272c90845
diff --git a/src/main/cpp/blaze_util_bsd.cc b/src/main/cpp/blaze_util_bsd.cc index 7d7e5c6..0a75dd5 100644 --- a/src/main/cpp/blaze_util_bsd.cc +++ b/src/main/cpp/blaze_util_bsd.cc
@@ -68,7 +68,7 @@ char buf[2048]; struct passwd pwbuf; struct passwd *pw = nullptr; - int uid = getuid(); + uid_t uid = getuid(); int r = getpwuid_r(uid, &pwbuf, buf, 2048, &pw); if (r == 0 && pw != nullptr) { xdg_cache_home = blaze_util::JoinPath(pw->pw_dir, ".cache");
diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc index e202a74..632f5a5 100644 --- a/src/main/cpp/blaze_util_linux.cc +++ b/src/main/cpp/blaze_util_linux.cc
@@ -53,7 +53,7 @@ char buf[2048]; struct passwd pwbuf; struct passwd *pw = nullptr; - int uid = getuid(); + uid_t uid = getuid(); int r = getpwuid_r(uid, &pwbuf, buf, 2048, &pw); if (r == 0 && pw != nullptr) { home = pw->pw_dir;
diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc index 5145c83..7cbd25f 100644 --- a/src/main/cpp/blaze_util_posix.cc +++ b/src/main/cpp/blaze_util_posix.cc
@@ -428,17 +428,17 @@ } posix_spawn_file_actions_t file_actions; - if (posix_spawn_file_actions_init(&file_actions) == -1) { + if (posix_spawn_file_actions_init(&file_actions) != 0) { BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR) << "Failed to create posix_spawn_file_actions: " << GetLastErrorString(); } - if (posix_spawn_file_actions_addclose(&file_actions, fds[0]) == -1) { + if (posix_spawn_file_actions_addclose(&file_actions, fds[0]) != 0) { BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR) << "Failed to modify posix_spawn_file_actions: "<< GetLastErrorString(); } posix_spawnattr_t attrp; - if (posix_spawnattr_init(&attrp) == -1) { + if (posix_spawnattr_init(&attrp) != 0) { BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR) << "Failed to create posix_spawnattr: " << GetLastErrorString(); } @@ -449,7 +449,7 @@ pid_t transient_pid; if (posix_spawn(&transient_pid, daemonize.c_str(), &file_actions, &attrp, - CharPP(daemonize_args).get(), CharPP(env).get()) == -1) { + CharPP(daemonize_args).get(), CharPP(env).get()) != 0) { BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR) << "Failed to execute JVM via " << daemonize << ": " << GetLastErrorString();