From 974fcc49e8b6892ab9c42e2bf69ca1eb61f4e4c7 Mon Sep 17 00:00:00 2001 From: Matt Callanan Date: Sat, 8 Oct 2022 03:11:32 +0200 Subject: Fix compilation errors under C++11. `std::string::data()` is const-only until C++17. PiperOrigin-RevId: 479708109 --- snappy.cc | 2 +- snappy_benchmark.cc | 2 +- snappy_unittest.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/snappy.cc b/snappy.cc index 6fe5f34..b072e5d 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..28570dd 100644 --- a/snappy_benchmark.cc +++ b/snappy_benchmark.cc @@ -164,7 +164,7 @@ void BM_UIOVecSource(benchmark::State& state) { 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; + iov[i].iov_base = const_cast(contents.data()) + used_so_far; if (used_so_far == contents.size()) { iov[i].iov_len = 0; continue; diff --git a/snappy_unittest.cc b/snappy_unittest.cc index aeb8044..122be0c 100644 --- a/snappy_unittest.cc +++ b/snappy_unittest.cc @@ -170,7 +170,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; - char* buf = copy.data(); + char* buf = const_cast(copy.data()); size_t num = 0; struct iovec* iov = GetIOVec(input, buf, num); const size_t written = snappy::CompressFromIOVec(iov, num, &compressed); -- cgit v1.2.1