Fix all c++ compile time warnings

This commit is contained in:
Andrei Vagin
2023-03-09 19:01:00 -08:00
parent c98ccb40b8
commit 6e719b44ce
24 changed files with 90 additions and 35 deletions
+1 -1
View File
@@ -227,7 +227,7 @@ network-tests: iptables-tests packetdrill-tests packetimpact-tests
.PHONY: network-tests
syscall-tests: $(RUNTIME_BIN) ## Run all system call tests.
@$(call test,--test_env=RUNTIME=$(RUNTIME_BIN) $(PARTITIONS) test/syscalls/...)
@$(call test,--test_env=RUNTIME=$(RUNTIME_BIN) --cxxopt=-Werror $(PARTITIONS) test/syscalls/...)
.PHONY: syscall-tests
packetimpact-tests:
+8 -8
View File
@@ -29,11 +29,11 @@ bazel_skylib_workspace()
# Load license rules.
http_archive(
name = "rules_license",
sha256 = "6157e1e68378532d0241ecd15d3c45f6e5cfd98fc10846045509fb2a7cc9e381",
urls = [
"https://github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.4/rules_license-0.0.4.tar.gz",
],
sha256 = "6157e1e68378532d0241ecd15d3c45f6e5cfd98fc10846045509fb2a7cc9e381",
)
# Load go bazel rules and gazelle.
@@ -1430,10 +1430,10 @@ http_archive(
name = "com_github_grpc_grpc",
patch_args = ["-p1"],
patches = ["//tools:grpc_extra_deps.patch"],
sha256 = "b55696fb249669744de3e71acc54a9382bea0dce7cd5ba379b356b12b82d4229",
strip_prefix = "grpc-1.51.1",
sha256 = "ec125d7fdb77ecc25b01050a0d5d32616594834d3fe163b016768e2ae42a2df6",
strip_prefix = "grpc-1.52.1",
urls = [
"https://github.com/grpc/grpc/archive/v1.51.1.tar.gz",
"https://github.com/grpc/grpc/archive/v1.52.1.tar.gz",
],
)
@@ -1457,11 +1457,11 @@ http_archive(
http_archive(
name = "com_google_benchmark",
sha256 = "3c6a165b6ecc948967a1ead710d4a181d7b0fbcaa183ef7ea84604994966221a",
strip_prefix = "benchmark-1.5.0",
sha256 = "6430e4092653380d9dc4ccb45a1e2dc9259d581f4866dc0759713126056bc1d7",
strip_prefix = "benchmark-1.7.1",
urls = [
"https://mirror.bazel.build/github.com/google/benchmark/archive/v1.5.0.tar.gz",
"https://github.com/google/benchmark/archive/v1.5.0.tar.gz",
"https://mirror.bazel.build/github.com/google/benchmark/archive/v1.7.1.tar.gz",
"https://github.com/google/benchmark/archive/v1.7.1.tar.gz",
],
)
+8
View File
@@ -8,6 +8,14 @@ package(
cc_binary(
name = "server_cc",
srcs = ["server.cc"],
# gcc reports the false warning:
# examples/seccheck/server.cc:147:19: error: 'buf' may be used uninitialized
# More details are here:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101831
copts = [
"-Wno-maybe-uninitialized",
"-Wno-unknown-warning-option",
],
visibility = ["//:sandbox"],
deps = [
# any_cc_proto placeholder,
+1 -1
View File
@@ -204,7 +204,7 @@ bool handshake(int client_fd) {
if (bytes < 0) {
printf("Error receiving handshake message: %d\n", errno);
return false;
} else if (bytes == buf.size()) {
} else if (bytes == (int)buf.size()) {
// Protect against the handshake becoming larger than the buffer allocated
// for it.
printf("handshake message too big\n");
+6
View File
@@ -1661,6 +1661,9 @@ cc_binary(
name = "poll_test",
testonly = 1,
srcs = ["poll.cc"],
copts = [
"-Wno-unknown-warning-option",
],
linkstatic = 1,
deps = [
":base_poll_test",
@@ -4077,6 +4080,9 @@ cc_binary(
name = "uidgid_test",
testonly = 1,
srcs = ["uidgid.cc"],
copts = [
"-Wno-unknown-warning-option",
],
linkstatic = 1,
deps = [
"//test/util:capability_util",
+5 -4
View File
@@ -18,6 +18,7 @@
#include <limits.h>
#include <sys/mount.h>
#include <unistd.h>
#include <cstdint>
#include "gtest/gtest.h"
#include "absl/container/flat_hash_map.h"
@@ -857,17 +858,17 @@ PosixErrorOr<std::vector<bool>> ParseBitmap(std::string s) {
for (const std::string_view& t : absl::StrSplit(s, ',')) {
std::vector<std::string> parts = absl::StrSplit(t, absl::MaxSplits('-', 2));
if (parts.size() == 2) {
ASSIGN_OR_RETURN_ERRNO(int64_t start, Atoi<int64_t>(parts[0]));
ASSIGN_OR_RETURN_ERRNO(int64_t end, Atoi<int64_t>(parts[1]));
ASSIGN_OR_RETURN_ERRNO(uint64_t start, Atoi<uint64_t>(parts[0]));
ASSIGN_OR_RETURN_ERRNO(uint64_t end, Atoi<uint64_t>(parts[1]));
// Note: start and end are indices into bitmap.
if (end >= bitmap.size()) {
bitmap.resize(end + 1, false);
}
for (int i = start; i <= end; ++i) {
for (uint64_t i = start; i <= end; ++i) {
bitmap[i] = true;
}
} else { // parts.size() == 1, 0 not possible.
ASSIGN_OR_RETURN_ERRNO(int64_t i, Atoi<int64_t>(parts[0]));
ASSIGN_OR_RETURN_ERRNO(uint64_t i, Atoi<uint64_t>(parts[0]));
if (i >= bitmap.size()) {
bitmap.resize(i + 1, false);
}
+1 -1
View File
@@ -178,7 +178,7 @@ TEST(ChrootTest, CreatesNewRoot) {
// getcwd should return "/".
TEST_CHECK_SUCCESS(syscall(__NR_getcwd, buf, sizeof(buf)));
TEST_CHECK_SUCCESS(strcmp(buf, "/") == 0);
TEST_PCHECK(strcmp(buf, "/") == 0);
// Statting '.', '..', '/', and '/..' all return the same dev and inode.
struct stat statbuf_dot;
+1 -1
View File
@@ -362,7 +362,7 @@ TEST_F(ForkTest, SigAltStack) {
MaybeSave();
TEST_CHECK((oss.ss_flags & SS_DISABLE) == 0);
TEST_CHECK(oss.ss_size == SIGSTKSZ);
TEST_CHECK(oss.ss_size == (size_t)SIGSTKSZ);
TEST_CHECK(oss.ss_sp == stack.ss_sp);
Exit(0);
+1 -1
View File
@@ -694,7 +694,7 @@ TEST_P(PrivateAndSharedFutexTest, PIWaiters) {
// Wait until the thread blocks on the futex, setting the waiters bit.
auto start = absl::Now();
while (a.load() != (FUTEX_WAITERS | gettid())) {
while (a.load() != (int)(gettid() | FUTEX_WAITERS)) {
ASSERT_LT(absl::Now() - start, absl::Seconds(5));
absl::SleepFor(absl::Milliseconds(100));
}
+2 -1
View File
@@ -23,6 +23,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <cstdint>
#include <functional>
#include <iostream>
#include <memory>
@@ -1042,7 +1043,7 @@ TEST(MountTest, SetMountPropagationOfStackedMounts) {
std::vector<ProcMountInfoEntry> mounts =
ASSERT_NO_ERRNO_AND_VALUE(ProcSelfMountInfoEntries());
int parent_mount_id;
uint64_t parent_mount_id;
for (const auto& e : mounts) {
if (e.mount_point == dir.path()) {
parent_mount_id = e.id;
+1 -1
View File
@@ -85,7 +85,7 @@ TEST_P(HostPipeTest, Write) {
ssize_t length = 0;
while (length < 1024 * 1024) {
char buf[1024];
for (int i = 0; i < sizeof(buf); ++i) {
for (unsigned int i = 0; i < sizeof(buf); ++i) {
buf[i] = i + lastValue;
}
+1 -1
View File
@@ -107,7 +107,7 @@ TEST(PivotRootTest, CreatesNewRoot) {
TEST_CHECK_SUCCESS(stat(file_in_new_root_new_path.c_str(), &statbuf));
// getcwd should return "/".
TEST_CHECK_SUCCESS(syscall(__NR_getcwd, buf, sizeof(buf)));
TEST_CHECK_SUCCESS(strcmp(buf, "/") == 0);
TEST_PCHECK(strcmp(buf, "/") == 0);
// Statting '.', '..', '/', and '/..' all return the same dev and inode.
struct stat statbuf_dot;
TEST_CHECK_SUCCESS(stat(".", &statbuf_dot));
+4
View File
@@ -41,6 +41,9 @@ class PollTest : public BasePollTest {
void TearDown() override { BasePollTest::TearDown(); }
};
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
#pragma GCC diagnostic ignored "-Wstringop-overflow"
TEST_F(PollTest, InvalidFds) {
// fds is invalid because it's null, but we tell ppoll the length is non-zero.
EXPECT_THAT(poll(nullptr, 1, 1), SyscallFailsWithErrno(EFAULT));
@@ -63,6 +66,7 @@ TEST_F(PollTest, NegativeTimeout) {
EXPECT_THAT(poll(nullptr, 0, -1), SyscallFailsWithErrno(EINTR));
EXPECT_TRUE(TimerFired());
}
#pragma GCC diagnostic pop
void NonBlockingReadableTest(int16_t mask) {
// Create a pipe.
+1 -1
View File
@@ -1255,7 +1255,7 @@ TEST(ProcCpuinfo, RequiredFieldsArePresent) {
// Check that the usual fields are there. We don't really care about the
// contents.
for (const std::string& field : required_fields) {
for (const char* field : required_fields) {
EXPECT_THAT(proc_cpuinfo, HasSubstr(field));
}
}
+5 -5
View File
@@ -52,7 +52,7 @@ class TestIovecs {
TestIovecs(std::vector<std::string>& data) {
data_ = std::vector<std::string>(data.size());
initial_ = std::vector<std::string>(data.size());
for (int i = 0; i < data.size(); ++i) {
for (size_t i = 0; i < data.size(); ++i) {
data_[i] = data[i];
initial_[i] = data[i];
struct iovec iov;
@@ -87,7 +87,7 @@ class TestIovecs {
std::vector<struct iovec*> marshal() {
std::vector<struct iovec*> ret(iovecs_.size());
for (int i = 0; i < iovecs_.size(); ++i) {
for (size_t i = 0; i < iovecs_.size(); ++i) {
ret[i] = &iovecs_[i];
}
return ret;
@@ -111,7 +111,7 @@ struct ProcessVMTestCase {
using ProcessVMTest = ::testing::TestWithParam<ProcessVMTestCase>;
bool ProcessVMCallsNotSupported() {
struct iovec iov;
struct iovec iov = {};
// Flags should be 0.
ssize_t ret = process_vm_readv(0, &iov, 1, &iov, 1, 10);
if (ret != 0 && errno == ENOSYS) return true;
@@ -245,7 +245,7 @@ INSTANTIATE_TEST_SUITE_P(
TEST(ProcessVMInvalidTest, NonZeroFlags) {
SKIP_IF(ProcessVMCallsNotSupported());
struct iovec iov;
struct iovec iov = {};
// Flags should be 0.
EXPECT_THAT(process_vm_readv(0, &iov, 1, &iov, 1, 10),
SyscallFailsWithErrno(EINVAL));
@@ -255,7 +255,7 @@ TEST(ProcessVMInvalidTest, NonZeroFlags) {
TEST(ProcessVMInvalidTest, NullLocalIovec) {
SKIP_IF(ProcessVMCallsNotSupported());
struct iovec iov;
struct iovec iov = {};
pid_t child = fork();
if (child == 0) {
while (true) {
+7 -2
View File
@@ -104,16 +104,21 @@ TEST_F(ReadvTest, BadFileDescriptor) {
iov[0].iov_base = buffer;
iov[0].iov_len = 1024;
ASSERT_THAT(readv(-1, iov, 1024), SyscallFailsWithErrno(EBADF));
ASSERT_THAT(readv(-1, iov, 1), SyscallFailsWithErrno(EBADF));
}
TEST_F(ReadvTest, BadIovecsPointer_File) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
ASSERT_THAT(readv(test_file_fd_.get(), nullptr, 1),
SyscallFailsWithErrno(EFAULT));
#pragma GCC diagnostic pop
}
TEST_F(ReadvTest, BadIovecsPointer_Pipe) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
ASSERT_THAT(readv(test_pipe_[0], nullptr, 1), SyscallFailsWithErrno(EFAULT));
#pragma GCC diagnostic pop
}
TEST_F(ReadvTest, BadIovecBase_File) {
+6
View File
@@ -139,13 +139,19 @@ TEST_F(ReadvSocketTest, ReadIovecsCompletelyFilled_DgramSocket) {
}
TEST_F(ReadvSocketTest, BadIovecsPointer_StreamSocket) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
ASSERT_THAT(readv(test_unix_stream_socket_[0], nullptr, 1),
SyscallFailsWithErrno(EFAULT));
#pragma GCC diagnostic pop
}
TEST_F(ReadvSocketTest, BadIovecsPointer_DgramSocket) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnonnull"
ASSERT_THAT(readv(test_unix_dgram_socket_[0], nullptr, 1),
SyscallFailsWithErrno(EFAULT));
#pragma GCC diagnostic pop
}
TEST_F(ReadvSocketTest, BadIovecBase_StreamSocket) {
+2 -2
View File
@@ -128,8 +128,8 @@ TEST(SigstopTest, RestartSyscall) {
pid_t pid;
constexpr absl::Duration kStopDelay = absl::Seconds(5);
constexpr absl::Duration kStartupDelay = absl::Seconds(5);
constexpr uint64_t kSleepDelay = 15;
constexpr uint64_t kErrorDelay = 3;
constexpr int64_t kSleepDelay = 15;
constexpr int64_t kErrorDelay = 3;
const DisableSave ds; // Timing-related.
+1 -1
View File
@@ -220,7 +220,7 @@ TEST_P(DataTransferStressTest, BigDataTransfer) {
const std::string chunk = "Though this upload be but little, it is fierce.";
std::string big_string;
while (big_string.size() < 31 << kShift) {
while (big_string.size() < size_t(31 << kShift)) {
big_string += chunk;
}
absl::string_view data = big_string;
+1 -1
View File
@@ -761,7 +761,7 @@ TEST_P(TcpSocketTest, TcpInq) {
TEST_P(TcpSocketTest, Tiocinq) {
char buf[1024];
size_t size = sizeof(buf);
int size = sizeof(buf);
ASSERT_THAT(RetryEINTR(write)(connected_.get(), buf, size),
SyscallSucceedsWithValue(size));

Some files were not shown because too many files have changed in this diff Show More