Use string_view::substr when making string_views out of other strings substr is both more convenient and also slightly safer when C++ hardening is enabled. PiperOrigin-RevId: 697644082
diff --git a/quiche/http2/adapter/oghttp2_session.cc b/quiche/http2/adapter/oghttp2_session.cc index 6d9bb13..7c4fabf 100644 --- a/quiche/http2/adapter/oghttp2_session.cc +++ b/quiche/http2/adapter/oghttp2_session.cc
@@ -778,8 +778,7 @@ } if (static_cast<size_t>(result) < frame.size()) { // The frame was partially written, so the rest must be buffered. - buffered_data_.Append( - absl::string_view(frame.data() + result, frame.size() - result)); + buffered_data_.Append(absl::string_view(frame).substr(result)); return SendResult::SEND_BLOCKED; } }
diff --git a/quiche/quic/core/crypto/crypto_secret_boxer.cc b/quiche/quic/core/crypto/crypto_secret_boxer.cc index e133a7f..bdc87e0 100644 --- a/quiche/quic/core/crypto/crypto_secret_boxer.cc +++ b/quiche/quic/core/crypto/crypto_secret_boxer.cc
@@ -129,14 +129,12 @@ absl::ReaderMutexLock l(&lock_); for (const bssl::UniquePtr<EVP_AEAD_CTX>& ctx : state_->ctxs) { size_t bytes_written; - if (EVP_AEAD_CTX_open(ctx.get(), - reinterpret_cast<uint8_t*>( - const_cast<char*>(out_storage->data())), - &bytes_written, ciphertext_len, nonce, - kSIVNonceSize, ciphertext, ciphertext_len, nullptr, - 0)) { + if (EVP_AEAD_CTX_open( + ctx.get(), reinterpret_cast<uint8_t*>(out_storage->data()), + &bytes_written, ciphertext_len, nonce, kSIVNonceSize, ciphertext, + ciphertext_len, nullptr, 0)) { ok = true; - *out = absl::string_view(out_storage->data(), bytes_written); + *out = absl::string_view(*out_storage).substr(0, bytes_written); break; }
diff --git a/quiche/quic/tools/quic_memory_cache_backend.cc b/quiche/quic/tools/quic_memory_cache_backend.cc index 5290636..1f64bf6 100644 --- a/quiche/quic/tools/quic_memory_cache_backend.cc +++ b/quiche/quic/tools/quic_memory_cache_backend.cc
@@ -40,7 +40,7 @@ << file_name_; return; } - file_contents_ = *maybe_file_contents; + file_contents_ = *std::move(maybe_file_contents); // First read the headers. for (size_t start = 0; start < file_contents_.length();) { @@ -54,12 +54,11 @@ if (file_contents_[pos - 1] == '\r') { len -= 1; } - absl::string_view line(file_contents_.data() + start, len); + auto line = absl::string_view(file_contents_).substr(start, len); start = pos + 1; // Headers end with an empty line. if (line.empty()) { - body_ = absl::string_view(file_contents_.data() + start, - file_contents_.size() - start); + body_ = absl::string_view(file_contents_).substr(start); break; } // Extract the status from the HTTP first line. @@ -137,8 +136,7 @@ if (it == responses_.end()) { uint64_t ignored = 0; if (generate_bytes_response_) { - if (absl::SimpleAtoi(absl::string_view(path.data() + 1, path.size() - 1), - &ignored)) { + if (absl::SimpleAtoi(path.substr(1), &ignored)) { // The actual parsed length is ignored here and will be recomputed // by the caller. return generate_bytes_response_.get();