From a5054767929fb750adff8248c6dc719f1adb135c Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Thu, 29 Sep 2022 09:46:03 -0700 Subject: [PATCH] Test: fix build error. --- snappy.cc | 2 +- snappy_benchmark.cc | 9 +++++---- snappy_unittest.cc | 6 +++--- third_party/benchmark | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/snappy.cc b/snappy.cc index 5457377..63c8432 100644 --- a/snappy.cc +++ b/snappy.cc @@ -2041,7 +2041,7 @@ size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt, std::string* compressed) { // Compute the number of bytes to be compressed. size_t uncompressed_length = 0; - for (int i = 0; i < iov_cnt; ++i) { + for (size_t i = 0; i < iov_cnt; ++i) { uncompressed_length += iov[i].iov_len; } diff --git a/snappy_benchmark.cc b/snappy_benchmark.cc index 0590142..e452855 100644 --- a/snappy_benchmark.cc +++ b/snappy_benchmark.cc @@ -158,21 +158,22 @@ void BM_UIOVecSource(benchmark::State& state) { std::string contents = ReadTestDataFile(kTestDataFiles[file_index].filename, kTestDataFiles[file_index].size_limit); + std::vector contents_copy(contents.begin(), contents.end()); // Create `iovec`s of the `contents`. const int kNumEntries = 10; struct iovec iov[kNumEntries]; size_t used_so_far = 0; for (int i = 0; i < kNumEntries; ++i) { - iov[i].iov_base = contents.data() + used_so_far; - if (used_so_far == contents.size()) { + iov[i].iov_base = contents_copy.data() + used_so_far; + if (used_so_far == contents_copy.size()) { iov[i].iov_len = 0; continue; } if (i == kNumEntries - 1) { - iov[i].iov_len = contents.size() - used_so_far; + iov[i].iov_len = contents_copy.size() - used_so_far; } else { - iov[i].iov_len = contents.size() / kNumEntries; + iov[i].iov_len = contents_copy.size() / kNumEntries; } used_so_far += iov[i].iov_len; } diff --git a/snappy_unittest.cc b/snappy_unittest.cc index aeb8044..005fa42 100644 --- a/snappy_unittest.cc +++ b/snappy_unittest.cc @@ -169,7 +169,7 @@ struct iovec* GetIOVec(const std::string& input, char*& buf, size_t& num) { int VerifyIOVecSource(const std::string& input) { std::string compressed; - std::string copy = input; + std::vector copy(input.begin(), input.end()); char* buf = copy.data(); size_t num = 0; struct iovec* iov = GetIOVec(input, buf, num); @@ -567,8 +567,8 @@ TEST(Snappy, FourByteOffset) { TEST(Snappy, IOVecSourceEdgeCases) { // Validate that empty leading, trailing, and in-between iovecs are handled: // [] [] ['a'] [] ['b'] []. - std::string data = "ab"; - char* buf = data.data(); + char data[3] = "ab"; + char* buf = data; size_t used_so_far = 0; static const int kLengths[] = {0, 0, 1, 0, 1, 0}; struct iovec iov[ARRAYSIZE(kLengths)]; diff --git a/third_party/benchmark b/third_party/benchmark index bf585a2..49aa374 160000 --- a/third_party/benchmark +++ b/third_party/benchmark @@ -1 +1 @@ -Subproject commit bf585a2789e30585b4e3ce6baf11ef2750b54677 +Subproject commit 49aa374da96199d64fd3de9673b6f405bbc3de3e