Fix `ZeroCopyCodedInputStream::ReadCord()`

`ZeroCopyCodedInputStream::ReadCord()` is implemented in terms of `CodedInputStream::ReadCord()` which is incorrect: the contract for the interface method `ZeroCopyInputStream::ReadCord()` is that it appends to the provided cord output where `CodedInputStream::ReadCord()` sets the cord output value, clearing any pre-existing contents. This change fixes the internal implementation to append to any pre-existing contents.

PiperOrigin-RevId: 500872467
pull/11465/head
Martijn Vels 2 years ago committed by Copybara-Service
parent 7cf6479295
commit 53eadba5ee
  1. 7
      src/google/protobuf/message_lite.cc

@ -204,8 +204,15 @@ class ZeroCopyCodedInputStream : public io::ZeroCopyInputStream {
bool aliasing_enabled() { return cis_->aliasing_enabled_; } bool aliasing_enabled() { return cis_->aliasing_enabled_; }
bool ReadCord(absl::Cord* cord, int count) final { bool ReadCord(absl::Cord* cord, int count) final {
// Fast path: tail call into ReadCord reading new value.
if (PROTOBUF_PREDICT_TRUE(cord->empty())) {
return cis_->ReadCord(cord, count); return cis_->ReadCord(cord, count);
} }
absl::Cord tmp;
bool res = cis_->ReadCord(&tmp, count);
cord->Append(std::move(tmp));
return res;
}
private: private:
io::CodedInputStream* cis_; io::CodedInputStream* cis_;
}; };

Loading…
Cancel
Save